Created
September 23, 2011 17:58
-
-
Save wolfsage/1238022 to your computer and use it in GitHub Desktop.
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/perl | |
use strict; | |
use warnings; | |
$|++; | |
use Time::HiRes qw(gettimeofday); | |
my $start; | |
my $end; | |
my $string = 'x' x (1024); | |
my $string2 = 'x' x (1024 * 1024 * 8); | |
print "Non-capture match against 1k: "; | |
$start = gettimeofday; | |
for (1..10_000) { | |
$string =~ /^x/; | |
} | |
$end = gettimeofday; | |
printf("%.02f seconds\n", $end - $start); | |
print "Non-capture match against 8MB bytes: "; | |
$start = gettimeofday; | |
for (1..10_000) { | |
$string2 =~ /^x/; | |
} | |
$end = gettimeofday; | |
printf("%.02f seconds\n", $end - $start); | |
print "Capture match against 1024 bytes: "; | |
$start = gettimeofday; | |
for (1..10_000) { | |
$string =~ /^(x)/; | |
} | |
$end = gettimeofday; | |
printf("%.02f seconds\n", $end - $start); | |
print "Capture match against 8MB bytes: "; | |
$start = gettimeofday; | |
for (1..10_000) { | |
$string2 =~ /^(x)/; | |
} | |
$end = gettimeofday; | |
printf("%.02f seconds\n", $end - $start); | |
mhorsfall@darmstadtium:~$ ./woah.pl | |
Non-capture match against 1k: 0.00 seconds | |
Non-capture match against 8MB bytes: 0.00 seconds | |
Capture match against 1024 bytes: 0.00 seconds | |
Capture match against 8MB bytes: 27.11 seconds |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment