To be a little bit more fair you should write the Squeak benchmark
exactly
like the C++ one:
| a | a := Array new: 1. 1 to: 10000000 do: [:i| a at: 1 put: 3.]
Using #to:do: gives a speed-up by 100% here!
-- Bert
PS: of course, we should change the implementation of #timesRepeat: accordingly
No, it is not "more fair". All Smalltalks run the same code, C++ was
here
just for... I don't know exactly why... just for fun?
I know that many fortran compilers would just optimize the whole loop away. Are you certain that the compiled C program wasn't also similiarily affected?
-- Travis Griggs
No, I supposed such optimizations, but I was wrong.
Here is disassembled code:
436: void CSelfDlg::OnBuildObject() 437: { 0040EF40 53 push ebx 0040EF41 55 push ebp 0040EF42 56 push esi 0040EF43 8B 35 28 40 41 00 mov esi,dword ptr [__imp__GetTickCount@0 (00414028)] 0040EF49 57 push edi 0040EF4A 8B D9 mov ebx,ecx 0040EF4C FF D6 call esi 438: DWORD BegTime = ::GetTickCount(); 439: DWORD *Array = new DWORD [1]; 0040EF4E 6A 04 push 4 0040EF50 8B E8 mov ebp,eax 0040EF52 E8 A5 31 00 00 call operator new (004120fc) 0040EF57 8B F8 mov edi,eax 0040EF59 83 C4 04 add esp,4 0040EF5C B8 80 96 98 00 mov eax,989680h 0040EF61 8B 0F mov ecx,dword ptr [edi] 440: for (DWORD Index = 0; Index < 10000000; Index++) 0040EF63 48 dec eax 441: { 442: Array [0] = 3; 0040EF64 B9 03 00 00 00 mov ecx,3 0040EF69 75 F8 jne CSelfDlg::OnBuildObject+23h (0040ef63) 0040EF6B 89 0F mov dword ptr [edi],ecx 443: }; 444: DWORD TotalTime = ::GetTickCount() - BegTime; 0040EF6D FF D6 call esi 0040EF6F 8B F0 mov esi,eax 445: delete Array; 0040EF71 57 push edi 0040EF72 2B F5 sub esi,ebp 0040EF74 E8 77 31 00 00 call operator delete (004120f0) 0040EF79 83 C4 04 add esp,4