Prev: VB 6 & VS?
Next: C:\WINDOWS\system32\ieframe.dll\1
From: dpb on 18 Mar 2010 20:38 Karl E. Peterson wrote: .... > ... I also added another test to do the vbSpeed > routine inline. ... > I expected that the native code results would be fastest. In no way did > I expect them to be immeasurable! Thoughts? My first guess would be the compiler was able to determine the dw variable was never used so simply optimized it all away. Did you check the generated code? --
From: Nobody on 18 Mar 2010 21:41 "Karl E. Peterson" <karl(a)exmvps.org> wrote in message news:OFif0pvxKHA.812(a)TK2MSFTNGP06.phx.gbl... > t(0) = 86 > t(1) = 86 - 86 = 0 > t(2) = 987 - 86 = 901 > t(3) = 1426 - 86 = 1340 > t(4) = 302 - 86 = 216 > Loops = 100000000 > > t(0) = 86 > t(1) = 86 - 86 = 0 > t(2) = 987 - 86 = 901 > t(3) = 1425 - 86 = 1339 > t(4) = 302 - 86 = 216 > Loops = 100000000 > > Now, why on Earth that t1 isn't showing *any* time over the loop overhead, > I just cannot say. Please check my work, and tell me I made a typo > somewhere? I really don't see it. I even moved that block around, and > swapped out the index in the t() entry. I tested your code, but without t(3) and t(4). Yes it's a case of optimization. I checked the assembly output and VB optimized the t(1) case out of the loop because "wd" was not used. When the only change that I made is moving "wd" from a local to a modal level variable, VB doesn't remove what's inside the loop. Here is the output, followed by the assembly output with all optimization selected("loops" = 1B): Output: t(0) = 840 t(1) = 840 - 840 = 0 t(2) = 12516 - 840 = 11676 t(3) = 0 - 840 = -840 t(4) = 0 - 840 = -840 Loops = 1000000000 Assembly for t(0) and t(1): 66: 67: ' Loop overhead 68: stp.Reset 004026E1 8B 45 E0 mov eax,dword ptr [stp] 004026E4 8B 10 mov edx,dword ptr [eax] 004026E6 50 push eax 004026E7 FF 52 28 call dword ptr [edx+28h] 004026EA DB E2 fnclex 004026EC 3B C7 cmp eax,edi 004026EE 7D 16 jge Form1::Command1_Click+0A6h (00402706) 004026F0 8B 4D E0 mov ecx,dword ptr [stp] 004026F3 8B 35 28 10 40 00 mov esi,dword ptr [__imp____vbaHresultCheckObj (00401028)] 004026F9 6A 28 push 28h 004026FB 68 74 1E 40 00 push offset ___vba(a)03A31910 (00401e74) 00402700 51 push ecx 00402701 50 push eax 00402702 FF D6 call esi 00402704 EB 06 jmp Form1::Command1_Click+0ACh (0040270c) 00402706 8B 35 28 10 40 00 mov esi,dword ptr [__imp____vbaHresultCheckObj (00401028)] 69: For dw = 1 To loops 0040270C BA 01 00 00 00 mov edx,1 00402711 B9 00 CA 9A 3B mov ecx,3B9ACA00h 00402716 8B C2 mov eax,edx 70: Next dw 00402718 3B C1 cmp eax,ecx 0040271A 7F 04 jg Form1::Command1_Click+0C0h (00402720) 0040271C 03 C2 add eax,edx 0040271E EB F8 jmp Form1::Command1_Click+0B8h (00402718) 71: t(0) = stp.Elapsed 00402720 8B 45 E0 mov eax,dword ptr [stp] 00402723 8B 10 mov edx,dword ptr [eax] 00402725 8D 4D A0 lea ecx,[unnamed_var1] 00402728 51 push ecx 00402729 50 push eax 0040272A FF 52 1C call dword ptr [edx+1Ch] 0040272D DB E2 fnclex 0040272F 3B C7 cmp eax,edi 00402731 7D 0E jge Form1::Command1_Click+0E1h (00402741) 00402733 8B 55 E0 mov edx,dword ptr [stp] 00402736 6A 1C push 1Ch 00402738 68 74 1E 40 00 push offset ___vba(a)03A31910 (00401e74) 0040273D 52 push edx 0040273E 50 push eax 0040273F FF D6 call esi 00402741 8B 45 A0 mov eax,dword ptr [unnamed_var1] 00402744 8B 4D D0 mov ecx,dword ptr [ebp-30h] 00402747 89 01 mov dword ptr [ecx],eax 72: 73: ' Best routine from vbSpeed, inline 74: stp.Reset 00402749 8B 45 E0 mov eax,dword ptr [stp] 0040274C 8B 10 mov edx,dword ptr [eax] 0040274E 50 push eax 0040274F FF 52 28 call dword ptr [edx+28h] 00402752 DB E2 fnclex 00402754 3B C7 cmp eax,edi 00402756 7D 0E jge Form1::Command1_Click+106h (00402766) 00402758 8B 4D E0 mov ecx,dword ptr [stp] 0040275B 6A 28 push 28h 0040275D 68 74 1E 40 00 push offset ___vba(a)03A31910 (00401e74) 00402762 51 push ecx 00402763 50 push eax 00402764 FF D6 call esi 75: For dw = 1 To loops 00402766 B9 01 00 00 00 mov ecx,1 0040276B 8B C1 mov eax,ecx 76: wd = _ 77: (((dw And &HFF000000) \ &H1000000) And &HFF&) Or _ 78: ((dw And &HFF0000) \ &H100&) Or _ 79: ((dw And &HFF00&) * &H100&) Or _ 80: ((dw And &H7F&) * &H1000000) 0040276D BB 00 CA 9A 3B mov ebx,3B9ACA00h 00402772 3B C3 cmp eax,ebx 00402774 7F 04 jg Form1::Command1_Click+11Ah (0040277a) 00402776 03 C1 add eax,ecx 00402778 EB F3 jmp Form1::Command1_Click+10Dh (0040276d) 81: If (dw And &H80&) Then wd = wd Or &H80000000 82: Next dw 83: t(1) = stp.Elapsed 0040277A 8B 45 E0 mov eax,dword ptr [stp] 0040277D 8B 10 mov edx,dword ptr [eax] 0040277F 8D 4D A0 lea ecx,[unnamed_var1] 00402782 51 push ecx 00402783 50 push eax 00402784 FF 52 1C call dword ptr [edx+1Ch] 00402787 DB E2 fnclex 00402789 3B C7 cmp eax,edi 0040278B 7D 0E jge Form1::Command1_Click+13Bh (0040279b) 0040278D 8B 55 E0 mov edx,dword ptr [stp] 00402790 6A 1C push 1Ch 00402792 68 74 1E 40 00 push offset ___vba(a)03A31910 (00401e74) 00402797 52 push edx 00402798 50 push eax 00402799 FF D6 call esi 0040279B 8B 45 A0 mov eax,dword ptr [unnamed_var1] 0040279E 8B 4D D0 mov ecx,dword ptr [ebp-30h] 004027A1 89 41 04 mov dword ptr [ecx+4],eax 84: Output with default optimization: t(0) = 840 t(1) = 7229 - 840 = 6389 t(2) = 9968 - 840 = 9128 t(3) = 0 - 840 = -840 t(4) = 0 - 840 = -840 Loops = 1000000000 Assembly for t(0) and t(1): 68: 69: ' Loop overhead 70: stp.Reset 004026E1 8B 45 E0 mov eax,dword ptr [stp] 004026E4 8B 08 mov ecx,dword ptr [eax] 004026E6 50 push eax 004026E7 FF 51 28 call dword ptr [ecx+28h] 004026EA DB E2 fnclex 004026EC 3B C3 cmp eax,ebx 004026EE 7D 16 jge Form1::Command1_Click+0A6h (00402706) 004026F0 8B 55 E0 mov edx,dword ptr [stp] 004026F3 8B 35 28 10 40 00 mov esi,dword ptr [__imp_@__vbaHresultCheckObj (00401028)] 004026F9 6A 28 push 28h 004026FB 68 74 1E 40 00 push offset ___vba(a)00236048 (00401e74) 00402700 52 push edx 00402701 50 push eax 00402702 FF D6 call esi 00402704 EB 06 jmp Form1::Command1_Click+0ACh (0040270c) 00402706 8B 35 28 10 40 00 mov esi,dword ptr [__imp_@__vbaHresultCheckObj (00401028)] 71: For dw = 1 To loops 0040270C BA 01 00 00 00 mov edx,1 00402711 B9 00 CA 9A 3B mov ecx,3B9ACA00h 00402716 8B C2 mov eax,edx 72: Next dw 00402718 3B C1 cmp eax,ecx 0040271A 7F 04 jg Form1::Command1_Click+0C0h (00402720) 0040271C 03 C2 add eax,edx 0040271E EB F8 jmp Form1::Command1_Click+0B8h (00402718) 73: t(0) = stp.Elapsed 00402720 8B 45 E0 mov eax,dword ptr [stp] 00402723 8B 08 mov ecx,dword ptr [eax] 00402725 8D 55 A4 lea edx,[unnamed_var1] 00402728 52 push edx 00402729 50 push eax 0040272A FF 51 1C call dword ptr [ecx+1Ch] 0040272D DB E2 fnclex 0040272F 3B C3 cmp eax,ebx 00402731 7D 0E jge Form1::Command1_Click+0E1h (00402741) 00402733 8B 4D E0 mov ecx,dword ptr [stp] 00402736 6A 1C push 1Ch 00402738 68 74 1E 40 00 push offset ___vba(a)00236048 (00401e74) 0040273D 51 push ecx 0040273E 50 push eax 0040273F FF D6 call esi 00402741 8B 45 D4 mov eax,dword ptr [ebp-2Ch] 00402744 8B 55 A4 mov edx,dword ptr [unnamed_var1] 00402747 89 10 mov dword ptr [eax],edx 74: 75: ' Best routine from vbSpeed, inline 76: stp.Reset 00402749 8B 45 E0 mov eax,dword ptr [stp] 0040274C 8B 08 mov ecx,dword ptr [eax] 0040274E 50 push eax 0040274F FF 51 28 call dword ptr [ecx+28h] 00402752 DB E2 fnclex 00402754 3B C3 cmp eax,ebx 00402756 7D 0E jge Form1::Command1_Click+106h (00402766) 00402758 8B 55 E0 mov edx,dword ptr [stp] 0040275B 6A 28 push 28h 0040275D 68 74 1E 40 00 push offset ___vba(a)00236048 (00401e74) 00402762 52 push edx 00402763 50 push eax 00402764 FF D6 call esi 77: For dw = 1 To loops 00402766 BB 01 00 00 00 mov ebx,1 0040276B 8B CB mov ecx,ebx 78: wd = _ 79: (((dw And &HFF000000) \ &H1000000) And &HFF&) Or _ 80: ((dw And &HFF0000) \ &H100&) Or _ 81: ((dw And &HFF00&) * &H100&) Or _ 82: ((dw And &H7F&) * &H1000000) 0040276D B8 00 CA 9A 3B mov eax,3B9ACA00h 00402772 3B C8 cmp ecx,eax 00402774 89 4D BC mov dword ptr [dw],ecx 00402777 7F 45 jg Form1::Command1_Click+15Eh (004027be) 00402779 8B C1 mov eax,ecx 0040277B 25 00 00 00 FF and eax,0FF000000h 00402780 99 cdq 00402781 81 E2 FF FF FF 00 and edx,0FFFFFFh 00402787 03 C2 add eax,edx 00402789 C1 F8 18 sar eax,18h 0040278C 33 D2 xor edx,edx 0040278E 8A D0 mov dl,al 00402790 8B C1 mov eax,ecx 00402792 83 E0 7F and eax,7Fh 00402795 C1 E0 18 shl eax,18h 00402798 8A 75 BE mov dh,byte ptr [ebp-42h] 0040279B 0B C2 or eax,edx 0040279D 8B D1 mov edx,ecx 0040279F 81 E2 00 FF 00 00 and edx,0FF00h 004027A5 C1 E2 08 shl edx,8 004027A8 0B C2 or eax,edx 83: If (dw And &H80&) Then wd = wd Or &H80000000 004027AA F6 C1 80 test cl,80h 004027AD 89 47 34 mov dword ptr [edi+34h],eax 004027B0 74 08 je Form1::Command1_Click+15Ah (004027ba) 004027B2 0D 00 00 00 80 or eax,80000000h 004027B7 89 47 34 mov dword ptr [edi+34h],eax 78: wd = _ 79: (((dw And &HFF000000) \ &H1000000) And &HFF&) Or _ 80: ((dw And &HFF0000) \ &H100&) Or _ 81: ((dw And &HFF00&) * &H100&) Or _ 82: ((dw And &H7F&) * &H1000000) 004027BA 03 CB add ecx,ebx 004027BC EB AF jmp Form1::Command1_Click+10Dh (0040276d) 84: Next dw 85: t(1) = stp.Elapsed 004027BE 8B 45 E0 mov eax,dword ptr [stp] 004027C1 8B 08 mov ecx,dword ptr [eax] 004027C3 8D 55 A4 lea edx,[unnamed_var1] 004027C6 52 push edx 004027C7 50 push eax 004027C8 FF 51 1C call dword ptr [ecx+1Ch] 004027CB DB E2 fnclex 004027CD 85 C0 test eax,eax 004027CF 7D 0E jge Form1::Command1_Click+17Fh (004027df) 004027D1 8B 4D E0 mov ecx,dword ptr [stp] 004027D4 6A 1C push 1Ch 004027D6 68 74 1E 40 00 push offset ___vba(a)00236048 (00401e74) 004027DB 51 push ecx 004027DC 50 push eax 004027DD FF D6 call esi 004027DF 8B 45 D4 mov eax,dword ptr [ebp-2Ch] 004027E2 8B 55 A4 mov edx,dword ptr [unnamed_var1] 004027E5 89 50 04 mov dword ptr [eax+4],edx 86: System: XP+SP2, 2.4GHz Quad CPU, 4 GB RAM, VB6+SP5 with SP6 runtime.
From: Nobody on 18 Mar 2010 21:48 "Nobody" <nobody(a)nobody.com> wrote in message news:uZxXLVwxKHA.3408(a)TK2MSFTNGP06.phx.gbl... > Yes it's a case of optimization. When I test some code for speed, I divide the code over one or more events because the compiler cannot know in advance which button or event will happen next.
From: Tony Toews [MVP] on 18 Mar 2010 23:34 Karl E. Peterson <karl(a)exmvps.org> wrote: >System is ... 10MB RAM You're showing your age. Errr, experience, yeah that's it experience. Tony -- Tony Toews, Microsoft Access MVP Tony's Main MS Access pages - http://www.granite.ab.ca/accsmstr.htm Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/ For a convenient utility to keep your users FEs and other files updated see http://www.autofeupdater.com/ Granite Fleet Manager http://www.granitefleet.com/
From: dpb on 19 Mar 2010 01:05
Karl E. Peterson wrote: > dpb wrote: >> Karl E. Peterson wrote: >> ... >> >>> ... I also added another test to do the vbSpeed routine inline. ... >> >>> I expected that the native code results would be fastest. In no way >>> did I expect them to be immeasurable! Thoughts? >> >> My first guess would be the compiler was able to determine the dw >> variable was never used so simply optimized it all away. >> >> Did you check the generated code? > > I didn't, no. That was my first guess, when I was using a fixed value > for dw, but I guess I just assumed that using the loop counter would've > tricked the compiler. Hmmmm, is it really *that* smart? I mean, > wouldn't it have seen that empty loop, too? Well, now you're down to the point of what optimizations the compiler uses and doesn't -- that's a tough 'un to know, a priori when the vendor doesn't publish such things. I'd make a guess that it doesn't see the empty loop because it's a higher level than the unused variable or there was a design decision that they wouldn't optimize empty loops because of their propensity as timing/delay structures. But, again, that's what the compiler writers chose to do that isn't amenable to anything except trying and finding out... .... > It definitely appears that optimizations were in play originally! But > how to predict? And why did they stop, with this slight jiggling of the > loop orders? See above... :) -- |