Created
December 28, 2011 20:32
-
-
Save viliampucik/1529594 to your computer and use it in GitHub Desktop.
Benchmark of Empty String Comparisons
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use Benchmark ( 'cmpthese' ); | |
my $foo = ''; | |
cmpthese( 10000000, { | |
'direct' => sub { return $foo eq '' }, | |
'length' => sub { return length $foo }, | |
'regexp' => sub { return $foo =~ /^$/ }, | |
}); | |
$foo = 'something'; | |
cmpthese( 10000000, { | |
'direct' => sub { return $foo eq '' }, | |
'length' => sub { return length $foo }, | |
'regexp' => sub { return $foo =~ /^$/ }, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment