Richard Gaskin wrote:
1. Using a function for a sortKey expression introduces a "sometimes"
rule in terms of understanding the order of expression evaluation in the
engine, in which most of the time functions are evaluated first but in
this case the function is applied repeatedly for each line of the sort
container as the sort command is run.
Well, not really. It's more like a substitution for what the engine does
anyway. When the engine sorts a container, it has to assign a position
for each element being sorted. A custom sort function does the same
thing; the engine will use the number returned by the function when
arranging the elements.
The order of evaluation hasn't changed, and functions are still
evaluated first. But when sorting, each element has to be evaluated
individually.
2. Using a function as a sortKey expression evaluates the sort container
as though by effectively adding data to it, rather than anything
necessarily in the data itself.
I guess you could think of it that way, but the paradigm seems a little
skewed to me. Sorting a container requires the engine to assign a
position to each element. If a custom sort function assigns a position
instead, the engine will use the number returned by the function.
Internally the engine is actually still assigning positions, but because
the function provides a straightforward numeric order, the engine
doesn't have to figure out what the order is, it just uses the numbers.
I don't think I'm explaining this very well. ;)
Given #1 above, how does this affect performance?
In my experience, not much. I suppose with a long list you might see a
difference though.
Unless there's
something ultra-tricky going on (wouldn't be the first time the engine
surprised me that way <g>), I would imagine that performance is affected
at least linearly, in which the overhead of the function call is
multiplied by the number of lines of the container to arrive at the
additional performance hit relative to a non-custom sort.
Perhaps I'll do some benchmarking to verify this theory....
Let us know.
--
Jacqueline Landman Gay | [EMAIL PROTECTED]
HyperActive Software | http://www.hyperactivesw.com
_______________________________________________
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution