Re: Interesting benchmark results - Euphoria vs. Euphoria

new topic     » goto parent     » topic index » view thread      » older message » newer message
ed_davis said...

... The Euphoria interpreter has gone from taking 12 seconds in 3.1 to 64 seconds in 4.1 to run the benchmark code. Not sure if anything can be done ...

The primary culprit has been the introduction of checking of GLOBAL variables and "better" dereferencing of temporary results.

As a general rules-of-thumb ...

  • Never use variables that are declared outside of a routine.
  • Explicitly use your own temporary result variable. This is not a big winner but may help sometimes, especially inside deeply nested loops.
  • Avoid combinations of 'and' and 'or' in a loop exit condition. This is one area that Euphoria needs some optimising work done.
  • Use the X op= Y operators instead of X = X op Y where possible

You can use the dis utility to view the generated Intermediate Language code generated by Euphoria's parser. This is the actual code that will be executed.

Here is your code with these suggestions included. On my system I got it down from 51 seconds to 21 seconds.

without type_check  
 
procedure main() -- Avoiding variables declared outside of routines. 
integer left_edge, right_edge, top_edge, bottom_edge, max_iter, x_step,  
    y_step, y0, x0, x, y, i, x_x, y_y, temp, the_char, accum, count  
 
atom t1    -- Explicit temporary used 
integer t2 -- Explicit temporary used 
   
atom t  
  
t = time()  
  
accum = 0  
count = 0  
while count < 1545 do  
    left_edge   = -420  
    right_edge  =  300  
    top_edge    =  300  
    bottom_edge = -300  
    x_step      =  7  
    y_step      =  15  
  
    max_iter    =  200  
  
    y0 = top_edge  
    while 1 do 
        if y0 <= bottom_edge then exit end if 
        x0 = left_edge  
        while 1 do 
            if x0 >= right_edge then exit end if  
            y = 0  
            x = 0  
            the_char = 32  
            x_x = 0  
            y_y = 0  
            i = 0 
            t1 = 0 
            while 1 do 
                if i >= max_iter then exit end if 
                if t1 > 800 then exit end if  
            	t1 = x * x 
                x_x = floor(t1 / 200)  
                t1 = y * y 
                y_y = floor(t1 / 200)  
                t1 = x_x + y_y 
                if t1 > 800 then  
                    the_char = 48 + i  
                    if i > 9 then  
                        the_char = 64  
                    end if  
                else  
                    temp = x_x - y_y 
                    temp = temp + x0  
                    t2 = x * y 
                    --if (x < 0 and y > 0) or (x > 0 and y < 0) then  
                    if t2 < 0 then 
                        t2 *= -1 
                        t1 = floor(t2 / 100) 
                        t1 *= -1 
                        y = t1 + y0 
                        --y = (-1 * floor((-1 * x * y) / 100)) + y0  
                    else  
                    	--t1 = x * y 
                    	t1 = floor(t2 / 100) 
                    	y = t1 + y0 
                        --y = floor(x * y / 100) + y0  
                    end if  
                    x = temp  
                end if  
  
                i = i + 1 
                t1 = x_x + y_y   
            end while  
            accum += the_char  
  
            x0 += x_step  
        end while  
  
        y0 -= y_step  
    end while  
  
    if remainder(count, 300) = 0 then  
        printf(1, "%d\n", accum)  
    end if  
  
    count += 1  
end while  
  
printf(1, "%d\n\nCompleted in %d seconds\n\n", {accum, time() - t})  
end procedure 
main() 
new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu