Skip to content

Instantly share code, notes, and snippets.

@niczero
Created March 31, 2017 12:57
Show Gist options
  • Save niczero/cc792d919ff7c32cbccf04fa821a1cb0 to your computer and use it in GitHub Desktop.
Save niczero/cc792d919ff7c32cbccf04fa821a1cb0 to your computer and use it in GitHub Desktop.
Benchmarking matrix transposition
perl -MMojo::Base=strict -Mojo -MMojar::Config -E'$a = Mojar::Config->load(q{matrix.conf})->{matrix}; my $width = @{$$a[0]}; my $height = @$a; n { my @cols = map { [map undef, 1 .. $height] } 1 .. $width; for (my $j = 0; $j < $height; ++$j) { for (my $i = 0; $i < $width; ++$i) { $cols[$i][$j] = $$a[$j][$i] } } } 1000'
# 18.3393 wallclock secs (18.31 usr + 0.01 sys = 18.32 CPU) @ 54.59/s (n=1000)
perl -MMojo::Base=strict -Mojo -MMojar::Config -E'$a = Mojar::Config->load(q{matrix.conf})->{matrix}; my $width = @{$$a[0]}; my $height = @$a; n { my @cols; push @cols, [] for 1 .. $width; for (my $i = 0; $i < $width; ++$i) { for (my $j = 0; $j < $height; ++$j) { push @{$cols[$i]}, $$a[$j][$i] } } } 1000'
# 17.6024 wallclock secs (17.58 usr + 0.00 sys = 17.58 CPU) @ 56.88/s (n=1000)
perl -MMojo::Base=strict -Mojo -MMojar::Config -E'$a = Mojar::Config->load(q{matrix.conf})->{matrix}; my $width = @{$$a[0]}; my $height = @$a; n { my @cols = map { my $i = $_; [ map $$a[$_][$i], 0 .. $height - 1] } 0 .. $width - 1 } 1000'
# 16.7276 wallclock secs (16.70 usr + 0.00 sys = 16.70 CPU) @ 59.88/s (n=1000)
perl -MMojo::Base=strict -Mojo -MMojar::Config -E'$a = Mojar::Config->load(q{matrix.conf})->{matrix}; my $width = @{$$a[0]}; my $height = @$a; n { my @cols; push @cols, [] for 1 .. $width; for (my $j = 0; $j < $height; ++$j) { for (my $i = 0; $i < $width; ++$i) { push @{$cols[$i]}, $$a[$j][$i] } } } 1000'
# 14.9494 wallclock secs (14.89 usr + 0.02 sys = 14.91 CPU) @ 67.07/s (n=1000)
perl -MMojo::Base=strict -Mojo -MList::Gen=tuples -MMojar::Config -E'$a = Mojar::Config->load(q{matrix.conf})->{matrix}; my $width = @{$$a[0]}; my $height = @$a; n { my @cols = tuples @$a } 1000'
# 13.258 wallclock secs (13.24 usr + 0.00 sys = 13.24 CPU) @ 75.53/s (n=1000)
say r $cols[0]; printf "%u x %u\n", scalar @{$cols[0]}, scalar @cols'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment