Jump to content
Sign in to follow this  
JRowe

Timing questions

Recommended Posts

JRowe

I wanted to see what the difference in using "1" and "True" as a condition was.

There is a slight difference, but it varies. I can't figure out what's causing one or the other to change.

Here's my test:

Global $one = 0
Global $true = 0
Global $numTests = 5000
Global $i = 0
Global $a = 0
Sleep(5000)

For $x = 1 To $numTests Step 1
    $i = 0
    $a = 0
    $stamp1 = TimerInit()
    While 1
        $i += 1
        If $i = 1000 Then ExitLoop
    WEnd
    $test1 = TimerDiff($stamp1)
    $one += $test1
    $stamp2 = TimerInit()
    While True
        $a += 1
        If $a = 1000 Then ExitLoop
    WEnd
    $test2 = TimerDiff($stamp2)
    $true += $test2
Next

ConsoleWrite("""While 1"" results in    :" & $one / $numTests & @CRLF)
ConsoleWrite("""While True"" results in :" & $true / $numTests & @CRLF)

This takes about 20 seconds from start to finish. Is this test statistically significant enough to display behavior?

The point being, I'd like to find out if "While 1" is faster or slower than "While True". "While 1" seems to be slower, but in some runs, is significantly faster.

I'm not sure how to make the determination, now.

I get weird results if I remove the Sleep from the test. It seems like it needs time to initialize.

Results also change if I switch the two functions position.

I am thoroughly confuzzled. Anyone know what's going on?

Share this post


Link to post
Share on other sites
monoceres

When will it ever matter?

Premature optimizing is the root of all evil.

The how and why of modern operating systems and especially modern processors is very complex. If you wish to examine and profile code and why it executes at certain speed you should be working in a compiled language such as C, not AutoIt where enormous amount of work are being done in the background.


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites
JRowe

I certainly can't conceive of where it would ever matter, because the overhead of an additional hundred thousandth of a second per loop cycle isn't significant.

I'm just curious. :mellow:

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×