ABS --fastest thus far

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

testing proposed code thus far, the two finalists are:

--carl's proposed abs, beat jiri's
function ABScarl(object x)
   return x*((x>0)-(x<0))
end function

--an alternative proposition by carl, with optimization
--seems compare is much faster than (x>0)-(x<0)
function ABSobj(object x)
   if not atom(x) then return x*compare({x},{0}) end if
   if x<0 then return -x else return x end if
end function

and their benchmarks are:
time ABScarl using atoms:1.480000
time ABSobj  using atoms:1.150000
time ABScarl using seq's:2.690000
time ABSobj  using seq's:0.930000

therefore:ABSobj is faster for both atoms and sequences.
(about 20% for atoms, and 250% for seq...)
also note:
        function ABSatom(atom x)
           if x<0 return -x else return x end if
        end function
is even faster than ABSobj if you *know* you only need atoms
mebbe ABSatom and ABSobj should both be in your toolbox??
/*  copies of prog used to benchmark I wrote are available
    if you realllllllyyyyyyyy doubt me that much :)
    you're welcome to make your own benchmarks as well :)
*/

can anyone beat carl's compare({x},{0}) suggestion?
can anyone beat
   if (x<0) then return -x else return x end if
for atoms?


happy thinking --Hawke'

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

Search



Quick Links

User menu

Not signed in.

Misc Menu