#!/usr/bin/env perl use strict; use warnings; use Benchmark 'cmpthese'; cmpthese 0 => { with_for => \&with_for, with_map => \&with_map, }; sub with_for { my @f; push @f, [$_+2, $_+1] for 0 .. 5; } sub with_map { my @f = map [$_+2, $_+1], 0 .. 5; } #### # 0 .. 5 Rate with_map with_for with_map 602818/s -- -23% with_for 780657/s 30% -- # 0 .. 40 Rate with_map with_for with_map 92655/s -- -23% with_for 120756/s 30% -- # 0 .. 5000 Rate with_map with_for with_map 745/s -- -23% with_for 968/s 30% --