[ create a new paste ] login | about

Link: http://codepad.org/lU3fifAP    [ raw code | fork ]

Perl, pasted on Sep 7:
#!/usr/bin/perl

use strict;
use warnings;

use Benchmark;

my @n = 0 .. 5;
my %subs = (
	void_map => sub {
		my @a = @n; #protect original
		map $_++, @a;
		return @a;
	},
	map => sub {
		my @a = @n; #protect original
		@a = map $_ + 1, @a;
		return @a;
	},
	for => sub {
		my @a = @n; #protect original
		$_++ for @a;
		return @a;
	},
);

for my $sub (keys %subs) {
	print "$sub: ", $subs{$sub}(), "\n";
}

for my $n (1, 10, 100, 1_000, 10_000) {
	print "\n$n items\n";
	@n = 1 .. $n;
	Benchmark::cmpthese -1, \%subs;
}


Create a new paste based on this one


Comments: