10e6
E:zcadothermaptests>E:zcadothermaptestshashmaptest.exe
Insert 2.023sec.
Calculate 1.407sec.
Sum=1784293664
Destroy 0.119sec.
10e7
E:zcadothermaptests>E:zcadothermaptestshashmaptest.exe
Insert 24.229sec.
Calculate 13.955sec.
Sum=-2004260032
Destroy 1.465sec.
Наши победили?
Плачевные результаты TMap судя по всему из-за особенностей его сравнения - он использует компоратор возвращающий boolean (т.е. либо больше либо меньше) dmap использует CompareStr и за одно сравнение понимает что больше-меньше-равно, TMap`у для этого приходится проводить 2 сравнения, цитата из fcl-stl про двоичный поиск:
- Код: Выделить всё
function TSet.NFind(value:T):PNode;inline;
var x:PNode;
begin
x:=FBase;
while(x <> nil) do begin
if(TCompare.c(value,x^.Data)) then x:=x^.Left
else if(TCompare.c(x^.Data,value)) then x:=x^.Right
else begin
exit(x);
end;
end;
exit(nil);
end;
такчто тмап не подойдет там где сравнение относительно дорого
Добавлено спустя 6 часов 12 минут 3 секунды:Лучший результат для THashMap у меня получился используя DelphiHashLittle из Generics.Hashes
10e6
E:zcadothermaptests>E:zcadothermaptestshashmaptest.exe
Insert 1.671sec.
Calculate 1.150sec.
Sum=1784293664
Destroy 0.272sec.
10e7
E:zcadothermaptests>E:zcadothermaptestshashmaptest.exe
E:zcadothermaptests>E:zcadothermaptestshashmaptest.exe
Insert 20.184sec.
Calculate 11.944sec.
Sum=-2004260032
Destroy 3.925sec.
Добавлено спустя 10 минут 13 секунд:Вариант от
serbod хоть и имхо академической ценности не имеет - приведу его циферки на моем компе
10е6
E:zcadothermaptests>E:zcadothermaptestsstringhashtest.exe
Insert 1.207sec.
Calculate 1.111sec.
Sum=1784293664
Destroy 0.212sec.
10е7
E:zcadothermaptests>E:zcadothermaptestsstringhashtest.exe
Insert 34.054sec.
Calculate 33.617sec.
Sum=-2004260032
Destroy 2.141sec.
Добавлено спустя 16 минут 28 секунд:java73давай реализацию с хэшем, сделаю подробный тест для 10,100,1000,10000,100000,1000000,10000000 ключей