From: Jim Freeze Date: 2001-11-22T07:30:46+09:00 Subject: [ruby-talk:26081] Re: positive On Thu, 22 Nov 2001, Niklas Frykholm wrote: > > something like > > 10.pos -> 10 > > -10.pos -> 0 > Here are some quick performance tests: def pos x # function here. See below end n = 100000 (-n..n).each { |i| pos i } [x,0].max real 0m2.499s user 0m2.348s sys 0m0.033s x > 0 ? x : 0 real 0m1.048s user 0m0.959s sys 0m0.009s x < 0 ? 0 : x real 0m1.049s user 0m0.951s sys 0m0.009s (x + x.abs)/2.0 real 0m2.676s user 0m2.541s sys 0m0.009s The one with the C like syntax is the fastest. ========================================================= Jim Freeze jim@freeze.org --------------------------------------------------------- Today is a fine day for Ruby programming. http://www.freeze.org =========================================================