Created
October 20, 2013 17:28
-
-
Save bessarabov/7072586 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
=encoding UTF-8 | |
=cut | |
=head1 DESCRIPTION | |
=cut | |
# common modules | |
use strict; | |
use warnings FATAL => 'all'; | |
use feature 'say'; | |
use utf8; | |
use open qw(:std :utf8); | |
use DDP; | |
use Carp; | |
use lib::abs qw( | |
./lib | |
); | |
use Perl6::Form; | |
use Math::Combinatorics qw(factorial); | |
# global vars | |
# subs | |
# main | |
sub main { | |
my @funcs = ( | |
{ | |
name => 'lg(n)', | |
expr => sub { log($_[0])/log(10); }, | |
}, | |
{ | |
name => 'sqrt(n)', | |
expr => sub { sqrt($_[0]); }, | |
}, | |
{ | |
name => 'n', | |
expr => sub { $_[0]; }, | |
}, | |
{ | |
name => 'n * lg(n)', | |
expr => sub { $_[0] * log($_[0])/log(10); }, | |
}, | |
{ | |
name => 'n ** 2', | |
expr => sub { $_[0] ** 2; }, | |
}, | |
{ | |
name => 'n ** 3', | |
expr => sub { $_[0] ** 3; }, | |
}, | |
{ | |
name => '2 ** n', | |
expr => sub { 2 ** $_[0]; }, | |
}, | |
{ | |
name => 'n!', | |
expr => sub { factorial($_[0]); }, | |
}, | |
); | |
my @times = ( | |
{ | |
name => '1 second', | |
seconds => 1, | |
}, | |
{ | |
name => '1 minute', | |
seconds => 60, | |
}, | |
# { | |
# name => '1 hour', | |
# seconds => 60 * 60, | |
# }, | |
# { | |
# name => '1 day', | |
# seconds => 60 * 60 * 24, | |
# }, | |
# { | |
# name => '1 month', | |
# seconds => 60 * 60 * 24 * 30, | |
# }, | |
# { | |
# name => '1 year', | |
# seconds => 60 * 60 * 24 * 30 * 365, | |
# }, | |
# { | |
# name => '1 century', | |
# seconds => 60 * 60 * 24 * 30 * 365 * 100, | |
# }, | |
); | |
my $format = ( "{". ("<"x15) . "} " ) x ( scalar(@times) + 1 ); | |
#print header | |
print form $format, | |
'', | |
map { $_->{name} } @times | |
; | |
my $microseconds_in_a_second = 1_000_000; | |
# print body | |
foreach my $f (@funcs) { | |
my @values; | |
foreach my $t (@times) { | |
my $n = $f->{expr}( $t->{seconds}) * $microseconds_in_a_second; | |
push @values, $n; | |
} | |
print form $format, | |
$f->{name}, | |
@values, | |
; | |
}; | |
# p \@times; | |
} | |
main(); | |
__END__ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment