Skip to content

Commit

Permalink
use Benchmark for i function
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Aug 10, 2014
1 parent a2f0556 commit cb8f27d
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions lib/ojo.pm
@@ -1,11 +1,11 @@
package ojo;
use Mojo::Base -strict;

use Benchmark qw(timeit :hireswallclock);
use Mojo::ByteStream 'b';
use Mojo::Collection 'c';
use Mojo::DOM;
use Mojo::JSON 'j';
use Time::HiRes qw(gettimeofday tv_interval);
use Mojo::Util qw(dumper monkey_patch);

# Silent one-liners
Expand All @@ -27,10 +27,10 @@ sub import {
a => sub { $caller->can('any')->(@_) and return $ua->server->app },
b => \&b,
c => \&c,
d => sub { _request($ua, 'DELETE', @_) },
g => sub { _request($ua, 'GET', @_) },
h => sub { _request($ua, 'HEAD', @_) },
i => \&_timer,
d => sub { _request($ua, 'DELETE', @_) },
g => sub { _request($ua, 'GET', @_) },
h => sub { _request($ua, 'HEAD', @_) },
i => sub (&@) { timeit($_[1] // 1, $_[0])->[0] },
j => \&j,
o => sub { _request($ua, 'OPTIONS', @_) },
p => sub { _request($ua, 'POST', @_) },
Expand All @@ -52,12 +52,6 @@ sub _request {
return $tx->res;
}

sub _timer (&@) {
my $start = [gettimeofday];
$_[0]->() for 1 .. $_[1] // 1;
return sprintf '%f', tv_interval($start, [gettimeofday]);
}

1;

=encoding utf8
Expand Down

0 comments on commit cb8f27d

Please sign in to comment.