#!/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; } #### Devel::Timer Report -- Total time: 1.3955 secs Interval Time Percent ---------------------------------------------- 01 -> 02 1.3502 96.75% a -> b 02 -> 03 0.0452 3.24% b -> c 03 -> 04 0.0001 0.00% c -> d 00 -> 01 0.0000 0.00% INIT -> a #### Devel::Timer Report -- Total time: 0.0042 secs Interval Time Percent ---------------------------------------------- 02 -> 03 0.0026 60.89% 1 -> 2 03 -> 04 0.0011 27.18% 2 -> 3 04 -> 05 0.0002 5.23% 3 -> 4 01 -> 02 0.0002 5.13% 0 -> 1 00 -> 01 0.0001 1.57% INIT -> 0