ssinyagin/torrus-newfeatures — comment on commit dac9229db3400c8721fbe769f27b94c8c89b3d17
File:  line 0
By djzort:

this this rather ridiculous extreme test. i realise of course its
totally off the planet but anyway.

--
#!/usr/bin/perl
use strict;
use warnings;
use Benchmark 'cmpthese';

my $iter = shift || -1;

my $list = 'abcdefghijklmnopqrstuvwxyz' x 10_000_000;

cmpthese (
$iter,
{

try_length => q|my $foo = length($list)|,
try_eq => q|my $foo = ($list eq '')|,

},
);
--

dean@soundwave:/tmp$ perl test.pl
Rate try_eq try_length
try_eq 10386838/s -- -41%
try_length 17476267/s 68% --

On 02/11/11 09:38, Stanislav Sinyagin wrote:
> actually not, if I take the full expression:
> time perl -e '$a=""; for $b (1..26) {$a .= $a . $b}; for $b (1..10000000) {$c = (length($a) > 0)}'
>
> real 0m1.186s
> user 0m1.146s
> sys 0m0.041s
> time perl -e '$a=""; for $b (1..26) {$a .= $a . $b}; for $b (1..10000000) {$c = (length($a) > 0)}'
>
> real 0m1.193s
> user 0m1.143s
> sys 0m0.046s
>

--
http://fragfest.com.au