#! perl use strict; use warnings; use Benchmark qw( :hireswallclock cmpthese timethese ); my $string = ".co.uk/Jobs/Company-Sector/C8A6446X4PND86M9WYJ/Tradewind/?APath=2.21.0.0.0"; cmpthese( timethese ( 1_000_000, { 'karlgoethebier' => sub { $string =~ m/.+\/.+\/.+\/.+\/(.+)\/.+/; return $1; }, 'athanasius' => sub { return (split '/', $string)[4] }, } ) ); #### 13:09 >perl 390_SoPW.pl Benchmark: timing 1000000 iterations of athanasius, karlgoethebier... athanasius: 5.19894 wallclock secs ( 5.15 usr + 0.00 sys = 5.15 CPU) @ 194250.19/s (n=1000000) karlgoethebier: 20.2485 wallclock secs (20.08 usr + 0.00 sys = 20.08 CPU) @ 49808.24/s (n=1000000) Rate karlgoethebier athanasius karlgoethebier 49808/s -- -74% athanasius 194250/s 290% -- 13:16 > #### #! perl use strict; use warnings; use Benchmark qw( :hireswallclock cmpthese timethese ); my $string = ".co.uk/Jobs/Company-Sector/C8A6446X4PND86M9WYJ/Tradewind/?APath=2.21.0.0.0"; cmpthese( timethese ( 1_000_000, { 'karlgoethebier' => sub { $string =~ m/.+\/.+\/.+\/.+\/(.+)\/.+/; return $1; }, 'karlgoethebier2' => sub { $string =~ m/.+?\/.+?\/.+?\/.+?\/(.+?)\/.+/; return $1; }, 'athanasius' => sub { return (split '/', $string)[4] }, } ) ); #### 13:28 >perl 390_SoPW.pl Benchmark: timing 1000000 iterations of athanasius, karlgoethebier, karlgoethebier2... athanasius: 4.91799 wallclock secs ( 4.88 usr + 0.00 sys = 4.88 CPU) @ 204792.14/s (n=1000000) karlgoethebier: 20.1721 wallclock secs (20.05 usr + 0.00 sys = 20.05 CPU) @ 49885.26/s (n=1000000) karlgoethebier2: 2.55908 wallclock secs ( 2.53 usr + 0.00 sys = 2.53 CPU) @ 395569.62/s (n=1000000) Rate karlgoethebier athanasius karlgoethebier2 karlgoethebier 49885/s -- -76% -87% athanasius 204792/s 311% -- -48% karlgoethebier2 395570/s 693% 93% -- 13:29 >perl 390_SoPW.pl