marielle wrote:FourthWorld wrote:Also, one difficulty in using "send" to route messages to scripts outside of the message path is that it's quite slower than the natural message path. For occasional use the performance penalty of "send" isn't much, but I tend toward solutions that go with the grain of the message path whenever possible, saving any extra clock cycles for features.
I didn't benchmark this. I never had any reason for concern.
Feedback from Dar suggested the cost was really minimal. Do you have any data on this yourself?
Comparing "send" vs. the natural message path shows the former to be only twice as slow, and "minimal" is relative since we're talking 0.004ms vs 0.002ms (see test script with results below). Used occasionally, the impact of "send" will probably never be noticed, but if used throughout heavily-accessed portions of a program it can add up.
My main point wasn't that "send" isn't useful; indeed it's been in the language since HyperTalk because it can be very useful at times.
But most importantly what I wanted to convey for newcomers is merely that while there's an infinite variety of ways to solve problems with Rev, there isn't really anything inherently wrong with the natural message path. It's been used quite effectively in hundreds of commercial products developed by teams from 1 to 25 team members. FrontScripts, backScripts, and libraries are all supported natively in the engine; they're fully tested, robust, and efficient means to satisfy Tom's request.
Here's the benchmark script I used to test the message path vs "send", "do", and getProp:
on mouseUp
put 100000 into n
--
-- Native message path:
put the millisecs into t
repeat n
doMe
end repeat
put (the millisecs - t)/n into t1
--
-- Send:
put the millisecs into t
repeat n
send "doMe" to btn 2
end repeat
put (the millisecs - t )/n into t2
--
-- Do:
put the millisecs into t
repeat n
do "doMe"
end repeat
put (the millisecs - t)/n into t3
--
-- getProp:
put the millisecs into t
repeat n
get the uWhat of this cd
end repeat
put (the millisecs - t)/n into t4
--
--
set the numberformat to "0.000"
put "Native: "& t1 &"ms" &cr\
&"Send: "&t2 &"ms" &cr\
&"Do: "&t3 &"ms" &cr\
&"Prop: "&t4 &"ms"
end mouseUp
The script depends on a button named "class" with this script:
getProp MyTest
return 4+4
end MyTest
And this script in the stack:
function MyTest
return 4+4
end MyTest
function MyObj
return the long ID of btn "Class"
end MyObj
The results I get here are:
Native: 0.002ms
Send: 0.004ms
Do: 0.004ms
Prop: 0.003ms