#!/usr/bin/perl use strict; use warnings; use Benchmark qw(cmpthese); my %case=( a => sub{ return 1*shift; }, b => sub{ return 2*shift; }, c => sub{ return 3*shift; }, d => sub{ return 4*shift; }, ); *my_a=$case{a}; *my_b=$case{b}; *my_c=$case{c}; *my_d=$case{d}; sub rstr{ return chr(int(rand(4))+97) } sub gto { goto $case{rstr()}; } sub rcl { $case{rstr()}->(@_); } sub als { my $f=rstr(); $f eq 'a' and return my_a(@_); $f eq 'b' and return my_b(@_); $f eq 'c' and return my_c(@_); $f eq 'd' and return my_d(@_); } cmpthese(1000000, { 'goto' => sub{ gto(55); }, 'refcall' => sub{ rcl(55); }, 'alias' => sub{ als(55); }, });