Manus-Magnus Posted January 22, 2004 Posted January 22, 2004 (edited) hello,Basicly it's optimisation support request... Or general C programming question...I have some function burning my CPU comparing variables with constant numbers.have have multiples ways to exit a loop but...What is the order from the fastest to the slowest compares with (i need order with all not the 1 fastest in this list):If $x <> [int number] then....If $x < [int number] then....If $x > [int number] then....If $x == [int number] then....If $x >= [int number] then....If $x <= [int number] then....The next question is: same thing but with strings. Edited January 22, 2004 by Manus-Magnus http://www.premiumwanadoo.com/manus-magnus/
MattNis Posted January 23, 2004 Posted January 23, 2004 (edited) Seems like ">" is the fastest expandcollapse popup$start = TimerStart() For $i = 0 To 262144 if $i == 262144 then $x=0 Next $equal = TimerStop($start) / 1000 $start = TimerStart() For $i = 0 To 262144 if $i >= 262144 then $x=0 Next $ge = TimerStop($start) / 1000 $start = TimerStart() For $i = 0 To 262144 if $i <= 262144 then $x=0 Next $le = TimerStop($start) / 1000 $start = TimerStart() For $i = 0 To 262144 if $i NOT = 262144 then $x=0 Next $ne = TimerStop($start) / 1000 $start = TimerStart() For $i = 0 To 262144 if $i < 262144 then $x=0 Next $less = TimerStop($start) / 1000 $start = TimerStart() For $i = 0 To 262144 if $i > 262144 then $x=0 Next $greater = TimerStop($start) / 1000 MsgBox(4096, "Execution time:", "==" & $equal & @LF & ">=" & $ge & @LF & "<=" & $le & @LF & "NOT=" & $ne & @LF & "<" & $less & @LF & ">" & $greater) Edited January 23, 2004 by MattNis [quote]I was busy waiting all night for the Columbus Day Bunny to come down my chimney and light fireworks in my pumpkin.There's so much wrong with that.Oh, I'm sorry, i forgot you were Jewish.[/quote]
Valik Posted January 23, 2004 Posted January 23, 2004 (edited) There are several things wrong with that test. First, == forces a string comparison, this adds tremendous overhead since it's doing a string compare instead of double compare. Secondly, the Not = test is done incorrectly. Not doesn't work like that Try this to prove it: If 1 Not = 2 Then MsgBox(4096, "", "Yay") The correct way to use Not is: If Not(1 = 2) Then MsgBox(4096, "", "Yay") The rest of the tests are unbalanced as follows: > - No assignment is performed, ever >= - One assignment is performed < - Assignment is performed every pass but the last pass <= - Assignment is performed every pass Running the tests to minimize the amount of asignments occurring, =, >=, <=, <, > all run in the 13 - 14 second range. Not() ran at over 19, but it assigned $x every time but one so it's result is invalid in relation to the others. >= and <= both assigned only once each. (Note: It's impossible to use this particular test to compare both = and Not because one is always going to perform assignment all but one time while the other will only assign once.) Edited January 23, 2004 by Valik
MattNis Posted January 23, 2004 Posted January 23, 2004 (edited) > and >= are still the quicker of all....though not by much and the times I got changed a negligeable amount from the first test I posted expandcollapse popup$start = TimerStart() For $i = 0 To 262144 if $i = $i-1 then $x=0 Next $equal = TimerStop($start) / 1000 $start = TimerStart() For $i = 0 To 262144 if $i >= $i+1 then $x=0 Next $ge = TimerStop($start) / 1000 $start = TimerStart() For $i = 0 To 262144 if $i <= $i-1 then $x=0 Next $le = TimerStop($start) / 1000 $start = TimerStart() For $i = 0 To 262144 if NOT($i = $i) then $x=0 Next $ne = TimerStop($start) / 1000 $start = TimerStart() For $i = 0 To 262144 if $i < $i-1 then $x=0 Next $less = TimerStop($start) / 1000 $start = TimerStart() For $i = 0 To 262144 if $i > $i+1 then $x=0 Next $greater = TimerStop($start) / 1000 MsgBox(4096, "Execution time:", "=" & $equal & @LF & ">=" & $ge & @LF & "<=" & $le & @LF & "!=" & $ne & @LF & "<" & $less & @LF & ">" & $greater) Edited January 23, 2004 by MattNis [quote]I was busy waiting all night for the Columbus Day Bunny to come down my chimney and light fireworks in my pumpkin.There's so much wrong with that.Oh, I'm sorry, i forgot you were Jewish.[/quote]
MattNis Posted January 23, 2004 Posted January 23, 2004 (edited) if 1 NOT = 2 then MsgBox(0, "","1 Wrong") if NOT(1 = 2) then MsgBox(0, "","2 Wrong") you were right about the above Edited January 23, 2004 by MattNis [quote]I was busy waiting all night for the Columbus Day Bunny to come down my chimney and light fireworks in my pumpkin.There's so much wrong with that.Oh, I'm sorry, i forgot you were Jewish.[/quote]
Manus-Magnus Posted January 23, 2004 Author Posted January 23, 2004 peace. Tx you guy i tested, you test saying > or < are the fastest logicial if it's bit calculated, and so, tx you so much. simply the idea of USE timer start/stop to test and optimize some points is the final answer i think. mm http://www.premiumwanadoo.com/manus-magnus/
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now