Skip to content

Instantly share code, notes, and snippets.

@wolfsage
Created September 23, 2011 17:58
Show Gist options
  • Save wolfsage/1238022 to your computer and use it in GitHub Desktop.
Save wolfsage/1238022 to your computer and use it in GitHub Desktop.
#!/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