use Time::HiRes; sub CheckNaughtiness() { my $text = 'x' x 10_000; # Create some non-small amount of data. # Calculate the overhead of a do-nothing loop. my $start = Time::HiRes::time(); for (my $i = 0; $i < 5_000; $i++) { } my $overhead = Time::HiRes::time() - $start; # Now calculate the time for the same number of simple matches. $start = Time::HiRes::time(); for (my $i = 0; $i < 5_000; $i++) { $text =~ m/^/ } my $delta = Time::HiRes::time() - $start; # A differential of 5 is just a heuristic. printf "It seems your code is %s (overhead=%.2f, delta=%.2f)\n", ($delta > $overhead*5) ? "naughty" : "clean", $overhead, $delta; } ----------------------------------------------------------------------------- Copyright 1997-2024 Jeffrey Friedl