#!/usr/bin/perl -- use strict; use warnings; use Benchmark qw' cmpthese '; BEGIN { *begin = sub {} } INIT { *init = sub {} } sub declared {} *runtime = sub {}; cmpthese(-3, { begin => sub { begin() for (1 .. 1000) }, init => sub { init() for (1 .. 1000) }, declared => sub { declared() for (1 .. 1000) }, runtime => sub { runtime() for (1 .. 1000) } }); __END__ #### $ perl temp.pl Rate declared init runtime begin declared 1663/s -- -0% -3% -6% init 1670/s 0% -- -3% -6% runtime 1722/s 4% 3% -- -3% begin 1772/s 7% 6% 3% -- $ perl temp.pl Rate begin init runtime declared begin 1607/s -- -1% -1% -9% init 1621/s 1% -- -1% -8% runtime 1630/s 1% 1% -- -8% declared 1770/s 10% 9% 9% -- $ perl temp.pl Rate declared runtime begin init declared 1622/s -- -2% -3% -4% runtime 1655/s 2% -- -1% -2% begin 1668/s 3% 1% -- -1% init 1686/s 4% 2% 1% -- $ perl temp.pl Rate runtime init begin declared runtime 1551/s -- -6% -7% -11% init 1658/s 7% -- -0% -5% begin 1661/s 7% 0% -- -4% declared 1737/s 12% 5% 5% --