use warnings; use Benchmark; use Inline C => Config => BUILD_NOISY => 1; use Inline C => <<'EOC'; void foo(AV * x) { dXSARGS; SV ** elem; int len, i; len = av_len(x) + 1; sp = mark; for(i = 0; i < len; i++) { elem = av_fetch(x, i, 0); XPUSHs(*elem); } PUTBACK; XSRETURN(len); } AV * bar(AV * x) { dXSARGS; SV ** elem; int len, i; sp = mark; len = av_len(x) + 1; for(i = 0; i < len; i++) { elem = av_fetch(x, i, 0); XPUSHs(*elem); } return x; } EOC $len = 2000000; @x = (); for(1 .. $len) {push @x, $_} timethese (1, { 'ref' => '$ret = bar(\@x)', 'list' => '@ret = foo(\@x)', }); #### Benchmark: timing 1 iterations of list, ref... list: 1 wallclock secs ( 0.36 usr + 0.11 sys = 0.47 CPU) @ 2.13/s (n=1 ) (warning: too few iterations for a reliable count) ref: 0 wallclock secs ( 0.11 usr + 0.00 sys = 0.11 CPU) @ 9.17/s (n=1 ) (warning: too few iterations for a reliable count)