A Small Speed Observation on Custom Properties
Gregory Lypny
gregory.lypny at videotron.ca
Tue Aug 21 12:38:21 EDT 2007
Hello Everyone,
I've only just begun using custom properties, and this may be old
news to many of you but just in case I thought I'd pass it along. I
created a bunch of custom properties for a field called Data. These
properties are integers that identify the column or item location in
a line where a particular piece of information is stored; for
example, the colStudentName of fld "Data" = 3 tells me that the
student's name is always the third item.
If you have to process many lines in such a field in a repeat loop,
it will go much faster if you put the values of the custom properties
into variables outside the loop and use the variables in the loop
rather than calling the custom properties themselves within the loop.
The second part of the handler below runs about ten times faster than
the first for a field with 100 lines. And the speed is not affected
by the fact that I initialized the variables using "add" instead of
"put".
Regards,
Gregory
on mouseUp
-- Retrieve the custom property in each pass of the repeat loop
put the long seconds into theStartTime
get fld "Data"
repeat for each line thisLine in it
put item (the colStudentName of fld "Data") of thisLine && \
item (the colTime of fld "Data") of thisLine && \
item (the colGrade of fld "Data") of thisLine & return after x
end repeat
put "Time with custom prop:" && the long seconds - theStartTime
put empty into x
-- Compare by saving the custom properties to variables
put the long seconds into theStartTime
get fld "Data"
add the colStudentName of fld "Data" into n
add the colTime of fld "Data" into t
add the colGrade of fld "Data" into g
repeat for each line thisLine in it
put item n of thisLine && \
item t of thisLine && \
item g of thisLine & return after x
end repeat
put return & "Time with variable:" && the long seconds -
theStartTime after msg
end mouseUp
More information about the use-livecode
mailing list