Skip to content

Commit

Permalink
fixup [time]
Browse files Browse the repository at this point in the history
  • Loading branch information
coke committed Sep 8, 2012
1 parent ed3a891 commit 868ef43
Showing 1 changed file with 32 additions and 32 deletions.
64 changes: 32 additions & 32 deletions src/Partcl/commands/time.pm
@@ -1,32 +1,32 @@
#sub time(*@args) {
# if +@args < 1 || +@args > 2 {
# error('wrong # args: should be "time command ?count?"');
# }
#
# my $command := @args[0];
# my $count;
# if +@args == 2 {
# $count := pir::set__iP(@args[1]);
# } else {
# $count := 1;
# }
#
# if $count == 0 {
# return '0 microseconds per iteration';
# }
#
# my $start := pir::time__N();
#
# my $loop := pir::set__IP($count);
# while $loop {
# eval($command);
# $loop--;
# }
# my $end := pir::time__N();
#
# my $ms_per := pir::set__IP(($end-$start)*1000000 / $count);
#
# ~$ms_per ~ ' microseconds per iteration';
#}
#
## vim: expandtab shiftwidth=4 ft=perl6:
sub time(*@args) {
if +@args < 1 || +@args > 2 {
error('wrong # args: should be "time command ?count?"');
}

my $command := @args[0];
my $count;
if +@args == 2 {
$count := pir::set__IP(@args[1]);
} else {
$count := 1;
}

if $count == 0 {
return '0 microseconds per iteration';
}

my $start := pir::time__N();

my $loop := pir::set__IP($count);
while $loop {
eval($command);
$loop--;
}
my $end := pir::time__N();

my $ms_per := pir::set__IP(($end-$start)*1000000 / $count);

~$ms_per ~ ' microseconds per iteration';
}

# vim: expandtab shiftwidth=4 ft=perl6:

0 comments on commit 868ef43

Please sign in to comment.