Mark Wieder wrote:
Here's mine again, but I like your benchmarks. I did this with a
single repeat loop rather than your nested one, but otherwise I think
we're testing the same thing. I didn't stress-test this the way you
did with large data clumps, so I think I'd trust your conclusions for
real-world applications.

on mouseUp
    local temp
    local s
    local accum

    put "XXX" into temp
    put the ticks into s
    repeat 1000000 -- yes, that's a million
        append temp, accum
    end repeat
    put the ticks - s into field 1
    answer length(accum)
end mouseUp

command append pNew, @pString
    put pNew after pString
end append

No doubt passing the variable by reference is much faster than requiring a copy, but both will be slower than doing the work inline (which is often non-copying by nature) because of the overhead of the separate function call.

To measure that overhead I made this quick test:

on mouseUp
   -- Number of iterations:
   put 10000 into n
   --
   -- Test 1: inline:
   put the millisecs into t
   repeat n
      get 1+1
   end repeat
   put the millisecs - t into t1
   --
   -- Test 2: function call:
   put the millisecs into t
   repeat n
      get foo()
   end repeat
   put the millisecs - t into t2
   --
   -- results:
   put t1 && t2
end mouseUp

function foo
   return 1+1
end foo

Here's the result:

0.0003 0.0014

On the one hand, the overhead seems quite impressive, with more than four times the performance when we can do the work inline rather than call out to a function.

But when we consider the absolute, rather than relative, time, that overhead is only ~0.0011 ms per call (on the relatively slow machine I tested on; on a Haswell i5 I'd expect it to be a small fraction of that).

So while it can add up in very lengthy processes like the monster files Geoff's working on, it's more than fast enough for the convenience function calls offer for factored, readable code.

--
 Richard Gaskin
 Fourth World
 LiveCode training and consulting: http://www.fourthworld.com
 Webzine for LiveCode developers: http://www.LiveCodeJournal.com
 Follow me on Twitter:  http://twitter.com/FourthWorldSys

_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Reply via email to