#!/bin/perl use strict; use warnings; use List::Util qw( first ); use Benchmark qw( cmpthese timethese ); my @arr = qw( foo bar baz qux cool foo bar baz qux ); my $manywords = 'TONS OF WORDS ' x 500; my $str = $manywords . 'I am cool ' . $manywords; my @invocation; my $results = timethese( 0, { 'word_altn' => sub { local $" = '|'; if( $str =~ /@arr/ ) { ++$invocation[0]; # print "Matched\n" } }, 'grep_block_index' => sub { if( grep { index($str, $_) !=-1 } @arr) { ++$invocation[1]; # print "Matched\n" } }, 'grep_expr_index' => sub { if( grep index($str, $_) !=-1, @arr) { ++$invocation[2]; # print "Matched\n" } }, 'first_index' => sub { if( first { index($str, $_) != -1 } @arr ) { ++$invocation[3]; #print "Matched\n" } }, 'first_regex' => sub { if( first { $str =~ /$_/ } @arr ) { ++$invocation[4]; #print "Matched\n" } }, 'grep_block_regex' => sub { if( grep { $str =~ /$_/ } @arr ) { ++$invocation[5]; #print "Matched\n" } }, }, 'none', ); print "@invocation\n"; die unless grep { $_>0 } @invocation == @invocation; cmpthese $results;