in reply to Benchmark diamond operator
#!/usr/bin/perl use strict; use warnings; use Benchmark::Forking qw( timethese cmpthese ); # UnixOS # use Benchmark qw(:all) ; # WindowsOS my @preserved = @ARGV; sub test_grep { @ARGV = @preserved; # restore original @ARGV my @matched = grep { $_ =~ /AGGT/ } <>; if (@matched) { for(@matched) { chomp $_; print "Grep: " . length($_) . "\n";} } close ARGV if eof; } sub test_while { @ARGV = @preserved; # restore original @ARGV my $count; while (<>) { if ($_ =~ /^>hsa/){ chomp (my $line = <>); $count .= length($line); $count .= " "; } } continue { close ARGV if eof; # reset $. each file } print "While: " . $count . "\n"; } my $results = timethese(2, { Grep => \&test_grep, While => \&test_whil +e }, 'none'); cmpthese( $results );
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Benchmark diamond operator
by thanos1983 (Parson) on May 09, 2017 at 14:55 UTC | |
by tobyink (Canon) on May 09, 2017 at 18:55 UTC | |
by thanos1983 (Parson) on May 10, 2017 at 08:50 UTC | |
by Discipulus (Canon) on May 09, 2017 at 20:07 UTC | |
by thanos1983 (Parson) on May 10, 2017 at 08:58 UTC |