On Jun 24, 2005, at 12:42 PM, Jim Bufalini wrote:

However, the "repeat with i =" form being slower than the "repeat for each"
was news to me!

Upon reflection, you might have wondered about that.

The key is that the first uses 'line i of x' in the loop. The length of time to get this value increases with i.

Normally, values are simply sequences of characters and values with multiple lines are simply values that contain some line-delimiter characters (coded the same as ASCII LF). Though it is possible that some internal optimization breaks these up into structured data or a line-index table is cached, it is reasonable to suspect that this is not the case. If there is no optimization to finding line n, then all characters form the start of the string to line n must be searched.

It is possible that some compiler optimization would look for line n in loops and convert, but our first assumption should be that it probably doesn't.

We might assume that 'for each' does not have this limitation. We might assume that 'for each' keeps one or more hidden character indexes in managing the loop.

Given such suspicions we might try some timing or ask on the list.

This does not currently apply to characters; 'char n of s' executes in constant time.

Even so...

We all are sometimes surprised by things that should jump out.  I am.

It should be mentioned in the docs. (And probably is and I don't know where.)

Dar

--
**********************************************
    DSC (Dar Scott Consulting & Dar's Lab)
    http://www.swcp.com/dsc/
    Programming and software
**********************************************

_______________________________________________
use-revolution mailing list
[email protected]
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution

Reply via email to