in reply to Re: how to multiply an array of number as fast as posible
in thread how to multiply an array of number as fast as posible
The problem with your benchmark is the calculation moves into floating point exception handling very early on.
If you avoid that by adding logs, using threads improve performance by 65%:
#! perl -slw use strict; use threads; use Time::HiRes qw[ time ]; { my $start = time; my $t = 0; $t += log( $_ ) for 230000..900000; printf "%.15f\n", $t;; printf "Took %.6f\n", time() - $start; } { my $start = time; my $thr = async { my $t = 0; $t += log( $_ ) for 230000..565000; return $t; }; my $t = 0; $t += log( $_ ) for 565001..900000; $t += $thr->join; printf "%.15f\n", $t;; printf "Took %.6f\n", time() - $start; } __END__ C:\test>junk32 8829606.110849546300000 Took 0.132204 8829606.110849652400000 Took 0.080650
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: how to multiply an array of number as fast as posible
by kennethk (Abbot) on Sep 02, 2010 at 17:32 UTC | |
by BrowserUk (Patriarch) on Sep 02, 2010 at 17:56 UTC |