doTest

  how faster is it when I avoid using DO
do performance




  the price of DO
At 10:08 23.03.99 -0800, Terry Schussler wrote on the pros and cons (mainly) 
of using DO:



>Performance costs for using DO:
>

>
>-- Welcome to Director --
>doTest (executed three successive times)
>-- 54
>-- 50
>-- 52
>
>callTest (executed three successive times)
>-- 15
>-- 15
>-- 15
>
>


The ratio of this performance costs differed when I tested it with dfw 6.02, 
NT4, pII 300Mhz (1:2 instead of 1:3), but the tendency is the same. I definately
agree with Terry's advice to use alternatives whereever it is suitable. Thanks 
for the fine examples. 

However, I don't think the speed of executing the called handler is different. 
I think Terry's test shows a difference in the time needed to find the handler 
that should be executed.

I extended that test script a bit in order to compare the performance costs 
when executing different handlers (and setting the number of iterations, 
since - look yourself)

testem "dummy",100000
-- "do: 706"
-- "call: 337"

testem "stringTest",100
-- "do: 200"
-- "call: 199"

So, it appears that the performance gain that can be reached by using call is 
substantial  (50%) with a very short handler but not very impressive (0,5%) 
with a slow routine.



----------------------------------------------------------
-- movie script "test"

on testem cmd,times
  dotest cmd,times
  callTest cmd,times
end


on doTest cmd,times
  startTimer
  repeat with loopCounter = 1 to times
    do cmd
  end repeat
  put "do:" && the timer
end doTest

on callTest cmd,times
  startTimer
  repeat with loopCounter = 1 to times
    call symbol(cmd), (script "test")
  end repeat
  put "call:" && the timer
end callTest

on dummy
  nothing
end


on stringTest
  replaceChar the scripttext of member "test","e","x"  
end


on replaceChar str, oldChar, newChar
  -- replaces all occurences of oldChar in str with newChar
  -- ok for use in small input, it would be slow for large text
  
  repeat while str contains oldChar
    put newChar into char (offset (oldChar, str)) of str
  end repeat
  return str
end


Home shock + cgi Bits 'n pieces Director Lingo Shocklets Contact










pageID=l_doTest