in reply to Re: Summing Up Array Elements By Group
in thread Summing Up Array Elements By Group
the input to get this was:Benchmark: timing 1000000 iterations of tin1, tin2, tin3... tin1: 1 wallclock secs ( 0.59 usr + 0.00 sys = 0.59 CPU) @ 16 +86340.64/s (n=1000000) tin2: 1 wallclock secs ( 0.75 usr + 0.00 sys = 0.75 CPU) @ 13 +33333.33/s (n=1000000) tin3: 3 wallclock secs ( 2.22 usr + 0.00 sys = 2.22 CPU) @ 45 +0450.45/s (n=1000000) Rate tin3 tin2 tin1 tin3 450450/s -- -66% -73% tin2 1333333/s 196% -- -21% tin1 1686341/s 274% 26% --
$results = timethese(1000000,{ tin1 => '$output[int($_/3)] += $arr[$_] for 0..@arr-1;', tin2 =>'$out[$_] = ($arr[(3*$_)]+$arr[(3*$_+1)]+$arr[(3*$_+2)]) for 0. +.(scalar(@arr)/3 - 1);', tin3=>'for (0..$k) { $output[$_] = $arr[$b] + $arr[$b+1] + $arr[$b +2]; $b += 3; } '}); Benchmark::cmpthese( $results );
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Summing Up Array Elements By Group
by ivancho (Hermit) on Jan 21, 2009 at 09:40 UTC | |
by ikegami (Patriarch) on Jan 21, 2009 at 12:59 UTC |