Re: Can OpenEuphoria Help Solve This?

new topic     » goto parent     » topic index » view thread      » older message » newer message

Phix has a way of being faster than OE.

The Phix algorithm from Rosetta Code:

integer a,b,c,d,e,g sequence f a=10000 f=repeat(floor(a/5) 
,8401) c=8400 e=0 while c>0 do g=2*c d=0 b=c while b>0 do  
d+=f[b]*a g-=1 f[b]=remainder(d, g) d=floor(d/g) g-=1 b-=1  
if b!=0 then d*=b end if end while printf(1,"%04d",e+floor 
(d/a)) c-=14 e = remainder(d,a) end while 

From Lua Rosetta Code:

a = {} 
n = 1000 
len = math.modf( 10 * n / 3 ) 
  
for j = 1, len do 
    a[j] = 2 
end 
nines = 0 
predigit = 0 
for j = 1, n do 
    q = 0 
    for i = len, 1, -1 do 
        x = 10 * a[i] + q * i 
        a[i] = math.fmod( x, 2 * i - 1 ) 
        q = math.modf( x / ( 2 * i - 1 ) ) 
    end 
    a[1] = math.fmod( q, 10 ) 
    q = math.modf( q / 10 ) 
    if q == 9 then 
        nines = nines + 1 
    else 
        if q == 10 then 
            io.write( predigit + 1 ) 
            for k = 1, nines do 
                io.write(0) 
            end 
            predigit = 0 
            nines = 0 
        else 
            io.write( predigit ) 
            predigit = q 
            if nines ~= 0 then 
                for k = 1, nines do 
                    io.write( 9 ) 
                end 
                nines = 0 
            end 
        end 
    end 
end 
print( predigit ) 

The test method:

atom t 
 
printf(1, "Phix\n" ) 
t = time() 
system( "p p_pi.ex" ) 
? time() - t 
 
printf(1, "\nPhix Compiled\n" ) 
-- you get a compiled program with: p -c p_pi.ex 
 
t = time() 
system( "./p_pi" ) 
? time() - t 
 
printf(1, "\nLuaJIT\n" ) 
t = time() 
system( "luajit pi.lua" ) 
? time() - t 

The test hardware:

  • hp netbook (atom!)
  • Bodhi Linux

The results

Phix is three time faster than LuaJIT.

Enough of a test, on my machine, to make Phix or OE preferable to Lua. It is also true that many programmers would choose Lua if Euphoria was not available.

_tom

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu