#!/usr/bin/perl # sub_speed.plx -- compare speed for calling sub package Foo; sub do_nothing { } package main; use strict; use warnings; use Benchmark qw( cmpthese ); my $foo = bless {}, 'Foo'; sub do_nothing { } cmpthese( -1, { k1 => sub { $foo->do_nothing }, k2 => sub { Foo->do_nothing }, k3 => sub { Foo::do_nothing }, k4 => sub { do_nothing }, k5 => sub { &do_nothing }, }); #### k2 1456626/s -- -17% -34% -36% -47% k1 1745245/s 20% -- -21% -23% -36% k4 2210645/s 52% 27% -- -3% -19% k3 2277634/s 56% 31% 3% -- -16% k5 2723258/s 87% 56% 23% 20% --