update perform 4
Documentation Version for Comments and Changes
You are invited to make any changes...add any comments.
Changes will `eventually` be merged into the offical documentation.
Leave any commnents here...
...
... back to index page OE documentation
interpretive overhead, so operations on sequences don't always win. The only solution is to time it both ways. The per-element cost is usually lower when you process a sequence in one statement, but there are overheads associated with allocation and deallocation of sequences that may tip the scale the other way.
Some Special Case Optimizations
Euphoria automatically optimizes certain special cases. x and y below could be variables or arbitrary expressions.
x + 1 -- faster than general x + y 1 + x -- faster than general y + x x * 2 -- faster than general x * y 2 * x -- faster than general y * x x / 2 -- faster than general x / y floor(x/y) -- where x and y are integers, is faster than x/y floor(x/2) -- faster than floor(x/y)
x below is a simple variable, y is any variable or expression:
x = append(x, y) -- faster than general z = append(x, y) x = prepend(x, y) -- faster than general z = prepend(x, y) x = x & y -- where x is much larger than y, -- is faster than general z = x & y
When you write a loop that "grows" a sequence, by appending or concatenating data onto it, the time will, in general, grow in proportion to the square of the number (N) of elements you are adding. However, if you can use one of the special optimized forms of append, prepend or concatenation listed above, the time will grow in proportion to just N (roughly). This could save you a huge amount of time when creating an extremely long sequence.
(You could also use repeat to establish the maximum size of the sequence, and then fill in the elements in a loop, as discussed below.)
Assignment with Operators
For greater speed, convert:
**left-hand-side = left-hand-side op expression**to:
**left-hand-side op= expression**For example:
-- Instead of ... some_val = some_val * 3 -- Use ... some_val *= 3
whenever left-hand-side contains at least two subscripts, or at least one subscript and a slice. In all simpler cases the two forms run at the same speed (or very close to the same).
Library / Built-In Routines
Some common routines are extremely fast. You probably couldn't do the job faster any other way, even if you used C or assembly language. Some of these are:
Low Level Memory Manipulation
Not Categorized, Please Help
|