update perform 2

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



With the current version of the interpreter, nested simple if's that compare integers are usually a bit faster than a single short-circuit if-statement e.g.:

if x > 20 then 
    if y = 0 then 
       ... 
    end if 
end if 
  • The speed of access to private variables, local variables and global variables is the same.
  • There is no performance penalty for defining constants versus plugging in hard-coded literal numbers. The speed of:
y = x * MAX 

is exactly the same as:

y = x * 1000 

where you've previously defined:

constant MAX = 1000 
  • There is no performance penalty for having lots of comments in your program. Comments are completely ignored. They are not executed in any way. It might take a few milliseconds longer for the initial load of your program, but that's a very small price to pay for future maintainability, and when you bind your program, or translate your program to C, all comments are stripped out, so the cost becomes absolute zero.

Measuring Performance

In any programming language, and especially in Euphoria, you really have to make measurements before drawing conclusions about performance.

Euphoria provides both execution-count profiling, as well as time profiling. You will often be surprised by the results of these profiles. Concentrate your efforts on the places in your program that are using a high percentage of the total time (or at least are executed a large number of times.) There's no point to rewriting a section of code that uses 0.01% of the total time. Usually there will be one place, or just a few places where code tweaking will make a significant difference.

You can also measure the speed of code by using the time() function. e.g.

atom t = time() 
for i = 1 to 10000 do 
    -- small chunk of code here 
end for 
? time() - t 

You might rewrite the small chunk of code in different ways to see which way is faster.

How to Speed-Up Loops

Profiling will show you the hot spots in your program. These are usually inside loops. Look at each calculation inside the loop and ask yourself if it really needs to happen every time through the loop, or could it be done just once, prior to the loop.

Converting Multiplies to Adds in a Loop

Addition is faster than multiplication. Sometimes you can replace a multiplication by the loop variable, with an addition. Something like:


    
Not Categorized, Please Help

Search



Quick Links

User menu

Not signed in.

Misc Menu