And here is what it gives:"out1ax$len" => sub { for (1 .. COUNT) { $tmp = out1() } }, "out1bx$len" => sub { for (1 .. COUNT) { $tmp = \out1() } }, "out2ax$len" => sub { for (1 .. COUNT) { $tmp = ${ out2() } } }, "out2bx$len" => sub { for (1 .. COUNT) { $tmp = out2() } },
out1ax100: 44 wallclock secs (43.20 usr + 0.01 sys = 43.21 CPU) @ 0.23/s (n=10) out1bx100: 42 wallclock secs (42.03 usr + 0.01 sys = 42.04 CPU) @ 0.24/s (n=10) out2ax100: 41 wallclock secs (40.59 usr + 0.00 sys = 40.59 CPU) @ 0.25/s (n=10) out2bx100: 2 wallclock secs ( 1.61 usr + 0.00 sys = 1.61 CPU) @ 6.21/s (n=10)So out2b (real return by reference) is much faster than out1b (take the reference of the result). So string copy does take place when Perl handles the return value of the function. Or did I miss something?
In reply to Re^2: How to avoid string copies in function calls?
by Anonymous Monk
in thread How to avoid string copies in function calls?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |