#!/usr/bin/perl use strict; use warnings; use Benchmark ':hireswallclock'; # enable hires wallclock (microseconds) timing if possible my $iterations = 1; my $regexEngineCode = sub { my $x = "the quick brown fox\n"; $x x= 107374182; print length $x . "\n"; ### 8 bytes less than 2^31. my $n=0; ++$n while $x =~ m[^.*$]mg; print $n . "\n"; ### finds all the lines. ### Add another line that pushes the length a few bytes over 2^ $x .= "the straw that broke the camel's back\n"; print length $x . "\n"; $n=0; ++$n while $x =~ m[^.*$]mg; print $n . "\n"; ### and it silently fails to find any of them. }; my $time = timeit($iterations, $regexEngineCode); print "It took ", timestr($time), "\n"; #### 2147483641107374182 Out of memory! real 1m29.931s user 0m50.376s sys 0m4.824s #### #!/usr/bin/perl use strict; use warnings; use Benchmark ':hireswallclock'; # enable hires wallclock (microseconds) timing if possible my $iterations = 1; my $regexEngineCode = sub { my $x = "the quick brown fox\n"; $x x= 107374182; print length $x; ### 8 bytes less than 2^31. my $n=0; ++$n while $x =~ m[^.*$]mg; print $n; ### finds all the lines. ### Add another line that pushes the length a few bytes over 2^ $x .= "the straw that broke the camel's back\n"; print length $x; $n=0; ++$n while $x =~ m[^.*$]mg; print $n . "\n"; ### and it silently fails to find any of them. }; my $time = timeit($iterations, $regexEngineCode); print "It took ", timestr($time), "\n"; #### 214748364010737418221474836780 It took 32.7849 wallclock secs (31.79 usr + 1.02 sys = 32.81 CPU) @ 0.03/s (n=1) real 0m32.942s user 0m31.839s sys 0m1.129s