<p>Am 21.07.2015 16:33 schrieb "Michael Van Canneyt" <<a href="mailto:michael@freepascal.org">michael@freepascal.org</a>>:<br>
><br>
><br>
><br>
> On Tue, 21 Jul 2015, Sven Barth wrote:<br>
><br>
><br>
>> Am 21.07.2015 12:13 schrieb "Michael Van Canneyt" <<a href="mailto:michael@freepascal.org">michael@freepascal.org</a>>:<br>
>>><br>
>>><br>
>>><br>
>>><br>
>>> On Mon, 20 Jul 2015, Serguei TARASSOV wrote:<br>
>>><br>
>>>> Hi all,<br>
>>>><br>
>>>> I did a small test to compare performance of TFPGMap and TFPHashList in<br>
>><br>
>> sequential and random accessing values by keys.<br>
>>>><br>
>>>> <a href="http://arbinada.com/main/en/node/1511">http://arbinada.com/main/en/node/1511</a><br>
>>>><br>
>>>> The results are not the same than expected.<br>
>>>> In theory, the hash map should give O(1) and O(log2 N) for the sorted<br>
>><br>
>> map.<br>
>>>><br>
>>>><br>
>>>> Any explanations and suggestions are welcome.<br>
>>><br>
>>><br>
>>><br>
>>> In my opinion there is a simple explanation:<br>
>>><br>
>>> As a general solution, using generics will always be slower than 'native'<br>
>><br>
>> classes.<br>
>>><br>
>>> The reason is that any generic implementation which does not place<br>
>><br>
>> restrictions on the types used,<br>
>>><br>
>>> will be forced to use CompareMem() and Move() for its implementation (as<br>
>><br>
>> do the classes in fgl). Even when the generic class is otherwise optimally<br>
>> programmed, calling these routines will always be slower than a direct<br>
>> comparision in 2 CPU registers in case of integers/pointers.<br>
>><br>
>> You are wrong with your assumptions regarding TFPGList: it does not use<br>
>> Move(). The base implementation in TFPSList does, but the generic class<br>
>> overrides that with an assignment. Otherwise for example Strings wouldn't<br>
>> work with TFPGList.<br>
><br>
><br>
> I am glad it is not as bad as I thought :)<br>
></p>
<p>I had the same feeling as you when I looked at the code the first time, but then I found out how it is really intended ^^</p>
<p>Regards,<br>
Sven</p>