Which one is faster ?

Lynch, Jonathan bnz2 at cdc.gov
Wed May 18 13:30:10 EDT 2005


I think the difference must be that, in my test, I was checking for
single thing.

If X = 1000000 then
  Do whatever
Else
  Do something else
End if




-----Original Message-----
From: use-revolution-bounces at lists.runrev.com
[mailto:use-revolution-bounces at lists.runrev.com] On Behalf Of Mark
Wieder
Sent: Wednesday, May 18, 2005 12:49 PM
To: How to use Revolution
Subject: Re: Which one is faster ?

Jonathan-

Wednesday, May 18, 2005, 8:28:21 AM, you wrote:

LJ> I ran a test on 500,000 records, testing between a single if-then
vs. a
LJ> single switch, and I found that the if-then was faster. It was
LJ> noticeably faster, but not hugely faster. I do not remember the
exact
LJ> difference - sorry.

Interesting. I found that counter-intuitive, so I checked things out
with 4W RevBench (thanks, Richard). I find that the switch statement
consistently runs some quite a bit faster on four tests. Obviously the
value of x here will be the major factor in determining the total run
time in the nested-if case.

-- test 1:
put 4 into x
switch x
 case 1
  put x into y
  break
 case 2
  put x into y
  break
 case 3
  put x into y
  break
 case 4
  put x into y
  break
 default
  put x into y
end switch

-- test2:
put 5 into x
if x = 1 then
  put x into y
else
  if x = 2 then
   put x into y
  else
   if x = 3 then
    put x into y
   else
    if x = 4 then
     put x into y
    else
     put x into y
    end if
   end if
  end if
end if

value of x:    % faster (100k runs):
1               0
2               15
3               25
4               35
5               35

-- 
-Mark Wieder
 mwieder at ahsoftware.net

_______________________________________________
use-revolution mailing list
use-revolution at lists.runrev.com
http://lists.runrev.com/mailman/listinfo/use-revolution




More information about the use-livecode mailing list