8 use Benchmark qw<cmpthese>;
10 use Scope::Upper qw<:words>;
11 BEGIN { *uplevel_xs = \&Scope::Upper::uplevel }
14 BEGIN { *uplevel_pp = \&Sub::Uplevel::uplevel }
18 sub foo_t { void { } }
20 sub foo_pp { uplevel_pp(0, sub { }) }
22 sub foo_xs { uplevel_xs { } }
24 print "\nuplevel to current scope:\n";
26 tare => sub { foo_t() },
27 pp => sub { foo_pp() },
28 xs => sub { foo_xs() },
31 sub bar_1_t { bar_2_t() }
32 sub bar_2_t { void() }
34 sub bar_1_pp { bar_2_pp() }
35 sub bar_2_pp { uplevel_pp(1, sub { }) }
37 sub bar_1_xs { bar_2_xs() }
38 sub bar_2_xs { uplevel_xs { } UP }
40 print "\nuplevel to one scope above:\n";
42 tare => sub { bar_2_t() },
43 pp => sub { bar_2_pp() },
44 xs => sub { bar_2_xs() },
47 sub hundred { 1 .. 100 }
49 sub baz_t { hundred() }
51 sub baz_pp { uplevel_pp(0, sub { 1 .. 100 }) }
53 sub baz_xs { uplevel_xs { 1 .. 100 } }
55 print "\nreturning 100 values:\n";
57 tare => sub { my @r = baz_t() },
58 pp => sub { my @r = baz_pp() },
59 xs => sub { my @r = baz_xs() },
63 my $tare_code = "sub { my \@c; \@c = caller(0) for 1 .. $n }->()";
65 print "\ncaller() slowdown:\n";
67 tare => sub { system { $^X } $^X, '-e', "use blib; use List::Util; $tare_code" },
68 pp => sub { system { $^X } $^X, '-e', "use blib; use Sub::Uplevel; $tare_code" },
69 xs => sub { system { $^X } $^X, '-e', "use blib; use Scope::Upper; $tare_code" },