quoting all names, the mystery (was Re: [ANN] News Reader Stack Available)
Dar Scott
dsc at swcp.com
Thu Jul 3 14:25:00 EDT 2003
On Thursday, July 3, 2003, at 12:15 PM, Alex Rice wrote:
> _HyperTalk 2.2 The Book_
>
> Says on p. 45. "Enclosing literals in quotation marks can result in
> considerable time savings-- up to 20% for loops with several hundred
> or thousand repetitions."
I think this means "--up to 20% which can be significant for loops with
several hundred or thousand repetitions." The loops shouldn't affect
the percentage.
> In this test you are accessing a UI object. I suspect that access is
> going to skew things. We know accessing fields is much slower than
> accessing variables... maybe the same with for buttons?
Uh. I thought the question was related to UI objects.
>
> But I ran my own test and can't discern any noticeable difference.
> Sometimes quoted literals is faster, sometimes unquoted literals is
> faster. The Hypertalk Book is so clear about this. Maybe we are not
> writing correct benchmarks?
OK.
I trimmed mine down to minimal without a loop.
on mouseUp
set the numberFormat to "0.000000"
put empty into field "Report"
put the long seconds into tEnd -- throw this one away
-- measure ambient time ;-)
put the long seconds into tStart
-- measure nothing
put the long seconds into tEnd
put tEnd-tStart into tCorrection
-- measure minimal quoted
put the long seconds into tStart
get "dummy"
put the long seconds into tEnd
put ((tEnd - tStart) - tCorrection) & " s " & it & " quoted" & LF
after field "Report"
-- measure minimal unquoted
put the long seconds into tStart
get dummy
put the long seconds into tEnd
put ((tEnd - tStart) - tCorrection) & " s " & it & " unquoted" & LF
after field "Report"
end mouseUp
The tCorrection simply is the time it takes to put the long seconds
into a variable which I need to subtract from my measurement. The
first long seconds is thrown away because it sometimes takes longer
than the others.
My typical results are like this:
0.000005 s dummy quoted
0.000014 s dummy unquoted
There is a consistent approximately 10-microsecond difference and about
a 1 to 3 ratio in time.
Here is where I see a mystery--
Suppose I insert this line at the start of the the minimal unquoted
test:
if 0 = 1 then put "cow" into dummy
The report at the end shows that 'get dummy' got empty. If I put that
at the end, then 'get dummy' got "dummy".
The method used seems to depend on whether a variable was created by
that line in compiling. If that is the case, why aren't the times the
same? I suspect there might be some decisions that have to wait until
execution time related to this but don't come into play in this case.
Dar Scott
More information about the use-livecode
mailing list