in reply to Re^2: Map Vs Foreach
in thread Map Vs Foreach
in particular seemed suspect to me. Also the order of memory allocation can affect benchmarks. When I ran the supplied code the foreach loop worked fine (5 seconds on my machine) but the map gave Out of memory!.@arr1 = map { push @arr1, ($_+ 2) } @data;
I can't say if that was faster, because it still gives Out of memory! Must be something to do with a temporary list (5.10.1 on Windows). Reducing the size of @data by a factor of 10 gives map taking around twice as long, and each taking under a second.sub mapsub { my @arr; @arr = map { ($_ + 2) } @data; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Map Vs Foreach
by Ratazong (Monsignor) on Nov 26, 2009 at 10:24 UTC | |
by ikegami (Patriarch) on Nov 26, 2009 at 16:16 UTC |