Thanks Jonathan,
----- Original Message -----
From: "Jonathan Johnson" <[EMAIL PROTECTED]>
On Oct 13, 2006, at 4:46 AM, Ronald Vogelaar wrote:
As it now appears, my tests were flawed.
As you can see, the item we're trying to test is only 1 statement out of
5. Instead, you should try this loop to benchmark such a short operation:
For j=0 to 100000000
i=i--1
i=i--1
i=i--1
i=i--1
...
This is what I normally do, but your tip how to exclude the loop overhead
itself is valuable. Thanks for that.
By unrolling the loop, you ensure that the overhead of the loop barely
affects the results. This should bring the results into the expected
range. The other thing to do is to run the tests multiple times. The OS
will often cycle the CPU when it's not being used, which can cause some
"startup" expense when it realizes it's actually being used for something
lengthy. By separating the tests into their own methods and calling them
individually, you can eliminate this aspect of things as well.
I usually start my tests with a loop that's not timed, just so there aren't
any 'start-up' expenses, however, I had forgotten about that this time.
Just FYI, the "i = i - -1" will be eventually compiled into a IA32 opcode
"sub" with an immediate value since we're subtracting a constant. "i = i
+ 1" will eventually be compiled into the "add" opcode with an immediate
value also. I'm guessing that these operations should be the exact same
number of CPU cycles because they are such similar and related
functionality, and Intel/AMD would get a lot of grief if they had
differing performances for add and sub :)
Yes, I suppose so. This is my kind of 'gaming' when I'm off: turning code
upside down and inside out, and testing code with even the most obvious and
predictable results. Some might consider it a waste of time (Of course I
disagree), but then, so is playing games ;) for which I don't care.
Ronald Vogelaar
http://www.rovosoft.com
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>