[fpc-pascal] Is the TFPGMap.KeyData()/TDictionary.TryGetValue() faster than TStringList.Values[]?

Michael Van Canneyt michael at freepascal.org
Thu Jan 14 08:43:03 CET 2016



On Wed, 13 Jan 2016, silvioprog wrote:

> Hello,
>
> I need two fast list features:
>
> Add(Key: string, Value: string);
> Get(Key: string, Value: string): string;
>
> So, I took a look at the `TFPGMap` (and `TDictionary` on Delphi) class. It
> is really a very nice option. But I tested the `TStringList` class too, and
> I was suprised with its performance. Please, run this small test in your
> environment (my env. is: FPC 3.1.1 / Delphi Seattle, both generating a 32
> bits EXE):
>
> http://pastebin.com/vxwhD9W0
>
> FPC result:
>
> TStringList: 00:00:14.988
> TMyList: 00:00:00.187
> TMyList: 00:00:00.219
> TStringList: 00:00:15.204
> Press [ENTER] to exit ...
>
> *(Delphi result:*
> *TStringList: 00:00:10.859*
> *TMyList: 00:00:00.016*
> *TMyList: 00:00:00.003*
> *TStringList: 00:00:11.453*
> *Press [ENTER] to exit ...**)*
>
> Is this test wrong, or is the `TStringList.Values[]` really slow?

TStringList.Values is extremely slow, this is known. 
It performs a simple linear search.

- THashedStringList from inifiles should be faster for name=value.
- for simple key=value pairs, contrns contains various hash lists.

You can include them in your tests to get a more complete picture.

Michael.


More information about the fpc-pascal mailing list