Strange Times
BlitzMax Forums/BlitzMax Programming/Strange Times
| ||
Running the following code takes ~1760 milliseconds to completeSuperStrict Delay 1000 Local starttime:Int starttime = MilliSecs() Local num:Int = 0 Local loopMax:Int = length()-1 For Local i:Int = 0 To loopMax num:+ 1 Next Print num Print MilliSecs()-starttime Function length:Int() Return 1000000000 End Function removing the -1 from the declaration of loopMax drops it by about 500 ms, regardless of whether I place the starttime initialisation before or after this line. why? |
| ||
The times I got only varied by around a millisecond. My first attempt was 40 ms longer for both tries than subsequent attempts, though, probably due to caching. |
| ||
Im getting the same gap as Pert, and its wierd, cos I thought "InLine", but if you swap the 1000000000 for the var loopmax, you get the longer result. I have the same Athlon64 3000 as pert, what do you have bill? SuperStrict Delay 1000 Local starttime:Int starttime = MilliSecs() Local num:Int = 0 For Local i:Int = 0 To 999999999 num:+ 1 Next Print num Print MilliSecs()-starttimeGives the longer result, but the first code with the -1 removed gives ~500 faster It has to be that starttime is being corrupted, but cannot see how |
| ||
Good, I'm not going crazy :) |
| ||
Happens for me too. One just happens to generate assembly code that is faster than the other right? |
| ||
One just happens to generate assembly code that is faster than the other right? Apparently so, but why would that affect the loop time? The loop uses the same variable in either one and placing the starttime portion after the loopMax declaration does nothing to speed it up. Surely a for loop is generated in the same way regardless of how the variable is assigned it's value? |
| ||
try this When doing timing tests, you should declare variables ahead of time and allow a delay for variable setup to occur before starting timer. In your case, the operation of subtracting 1 from length() and the overhead of assigning the result to loopMax caused the extra delay which you didn't get without the subtraction. By declaring the variables first and the Delay 1000 to allow overhead, that will allow the program to time only the loop itself and the times are more to what's expected. |
| ||
nope, still does it. As I said above, regardless of whether I initialize my starttime before or after the declaration of loopMax. |
| ||
I spent quite a long time last night puttint starttime2s and 3s everywhere. And It has to be starttime being corrupted. It cannot really be simply that its faster. But anyway, Its somthing I cannot stop from happening if it really happens, so Im going to just wait until someone tells me why. |
| ||
the same on my PC with/without the -1 in non-debug mode = 480ms. |
| ||
strangely my Dad's machine doesn't do it (or at least the difference is minimal (less than 10ms), he has an Athlon 3200 |
| ||
maybe a register thing...? I get the same results if I subtract 1 from millisecs "starttime = MilliSecs()-1" instead of "length()". If I declare and initialize the var ahead of the timing I get consistant results with or without the "-1" but they are now 50% slower than the fastest result but 500 ms faster than perts code on my machine. pert's original except prints moved out of timing SuperStrict Delay 1000 Local starttime:Int starttime = MilliSecs() Local num:Int = 0 Local loopMax:Int = length()-1 For Local i:Int = 0 To loopMax num:+ 1 Next starttime = MilliSecs()-starttime Print num Print starttime Function length:Int() Return 1000000000 End FunctionI avg 1900 no subtraction SuperStrict Delay 1000 Local starttime:Int starttime = MilliSecs() Local num:Int = 0 Local loopMax:Int = length() For Local i:Int = 0 To loopMax num:+ 1 Next starttime = MilliSecs()-starttime Print num Print starttime Function length:Int() Return 1000000000 End FunctionI avg 956 declare ahead of time SuperStrict Delay 1000 Local starttime:Int Local num:Int = 0 Local loopMax:Int = length() starttime = MilliSecs() For Local i:Int = 0 To loopMax num:+ 1 Next starttime = MilliSecs()-starttime Print num Print starttime Function length:Int() Return 1000000000 End FunctionI avg 1435 all of these were run in release. |
| ||
the problem doesn't happen if you multiply or divide by 1 but adding or subtracting 1 will see the delay. |
| ||
Do you think this could be an Athlon vs Intel thing? I have a P4 3.2GHz HT. |
| ||
I would also like to know, why Greys P4 3.2 is three times faster than my Athlon64 3000 Infact why are all of dmaz's figures faster than mine by about 25% Ive just checked and Ive got a 3200+, which is more than I thought I had, and so still begs the question why is mine so slow |
| ||
http://www.blitzbasic.com/Community/posts.php?topic=63966 |
| ||
I'm seeing: 1807 using the length()-1 1555 using just length() AMD Athlon 2800+ |
| ||
I get ~1900 with the -1, and ~1300 without, but with this...SuperStrict Delay 1000 Local starttime:Int starttime = MilliSecs() Local num:Int = 0 Local loopMax:Int = length()-1 Local i:Int For i = 0 To loopMax num:+ 1 Next Print num Print MilliSecs()-starttime Function length:Double() Return 1000000000 End FunctionI get ~1200, whether the -1 is in or not. ;) EDIT - It seems Long suffers the same as Int. |
| ||
see you've all got athlons, and I guess "Bad cache boundaries" ;-) |
| ||
Running all three of dmaz's versions, I consistently get ~1300, results being within a handful of milliseconds of one another. I have an Athlon 64 X2 Dual Core 4600+ with two gigs of cheapo RAM. Edit: Interestingly, changing the target from 1,000,000,000 to 10,000,000,000 only adds about 40% to the execution time. Edit again: Nevermind, it's INT, I didn't notice that. SpaceAce |
| ||
Runnin the original code posted by Pert I get 1580. Athlon64 3200+ 939. |
| ||
@Leiden, you have to remove the -1 and post the two different times. The thread is about the difference between thesse two |
| ||
now try it like this:SuperStrict Delay 1000 Local starttime:Int starttime = MilliSecs() Local num:Int = 0 Local loopMax:Int = length()-1# For Local i:Int = 0 To loopMax num:+ 1 Next Print num Print MilliSecs()-starttime Function length:Int() Return 1000000000 End Function I get: 1057 with out subtractiong 1671 with -1 1057 with -1# ???????????? |
| ||
1287 -1# 1934 1290 -1 |