#!/usr/bin/perl use warnings; use strict; use Devel::Timer; my $target = 'a' x 100; search (); sub search { my $t = Devel::Timer->new; $t->mark('a'); validate_search_index (); $t->mark('b'); my @first_results = another_search (); $t->mark('c'); my @results; if (@first_results) { $target =~ /y/ for (1..10_000); my @second_results = ('a') x 100; foreach my $i (@first_results) { foreach my $j (@second_results) { push @results, [ $i, $j ]; } } } $t->mark('d'); $t->report; return @results; } sub another_search { $target =~ /y/ for (1..10_000); return (1) x 100; } sub validate_search_index { my $t = Devel::Timer->new; $t->mark(0); $target =~ /y/ for (0..10000); $t->mark(1); my @the_list = list_of_something (); $t->mark(2); my @other_list; if (@the_list) { $target =~ /y/ for (0..10000); @other_list = (1) x 100; } $t->mark(3); foreach (@the_list) { $target =~ /y/ for (0..10000); } $t->mark(4); $t->report; } sub list_of_something { $target =~ /y/ for (1..10_000); my @results; foreach (1..100) { $target =~ /y/ for (1..10_000); push @results, $_; $target =~ /y/ for (1..10_000); push @results, $_; } return @results; }