Using perl Syntax Highlighting
use strict;
use warnings;
use Benchmark ":all";
$|++;
my @arr = (5, 4, 3.14151926, 999786, 5.178591e37, 14e-33);
cmpthese(1000000, {
'sqrt' => sub {my $s = 0; $s += sqrt($_) foreach(@arr);},
'**1/2 ' => sub {my $s = 0; $s += $_ ** 0.5 foreach(@arr);}
});
use warnings;
use Benchmark ":all";
$|++;
my @arr = (5, 4, 3.14151926, 999786, 5.178591e37, 14e-33);
cmpthese(1000000, {
'sqrt' => sub {my $s = 0; $s += sqrt($_) foreach(@arr);},
'**1/2 ' => sub {my $s = 0; $s += $_ ** 0.5 foreach(@arr);}
});
Coloreado en 0.002 segundos, usando GeSHi 1.0.8.4
Resultados:
- Código: Seleccionar todo
Rate **1/2 sqrt
**1/2 140964/s -- -15%
sqrt 165344/s 17% --