in reply to Which is better when doing a simple match?
reveals#!/usr/local/bin/perl -w use Benchmark; $count = 1_000_000; print "Match eq => ", check_eq(), "\n"; print "Match rx => ", check_rx(), "\n"; timethese( $count, { 'eq' => sub{ check_eq() }, 'rx' => sub{ check_rx() } } ); sub check_eq { my $thing = "thing"; my $i = 0; $i++ if( $thing eq "thing" ); $i; } sub check_rx { my $thing = "thing"; my $i = 0; $i++ if( $thing =~ /^thing$/ ); $i; }
Match eq => 1 Match rx => 1 Benchmark: timing 1000000 iterations of eq, rx... eq: 15 wallclock secs (14.27 usr + 0.00 sys = 14.27 CPU) @ 70 +093.46/s (n=1000000) rx: 22 wallclock secs (21.08 usr + 0.00 sys = 21.08 CPU) @ 47 +430.83/s (n=1000000)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Which is better when doing a simple match?
by Cine (Friar) on Aug 22, 2001 at 00:42 UTC |