-
-
Save anonymous/47928ea73169b0fc7e7d 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
diff --git a/lib/ojo.pm b/lib/ojo.pm | |
index 05b5337..6ea158a 100644 | |
--- a/lib/ojo.pm | |
+++ b/lib/ojo.pm | |
@@ -5,6 +5,7 @@ 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 | |
@@ -29,6 +30,7 @@ sub import { | |
d => sub { _request($ua, 'DELETE', @_) }, | |
g => sub { _request($ua, 'GET', @_) }, | |
h => sub { _request($ua, 'HEAD', @_) }, | |
+ i => \&_timer, | |
j => \&j, | |
o => sub { _request($ua, 'OPTIONS', @_) }, | |
p => sub { _request($ua, 'POST', @_) }, | |
@@ -50,6 +52,12 @@ sub _request { | |
return $tx->res; | |
} | |
+sub _timer (&) { | |
+ my $start = [gettimeofday]; | |
+ shift->(); | |
+ return sprintf '%f', tv_interval($start, [gettimeofday]); | |
+} | |
+ | |
1; | |
=encoding utf8 | |
@@ -134,6 +142,14 @@ L<Mojo::Message::Response> object. | |
Perform C<HEAD> request with L<Mojo::UserAgent/"head"> and return resulting | |
L<Mojo::Message::Response> object. | |
+=head2 i | |
+ | |
+ my $seconds = i {...}; | |
+ | |
+Measure time it took to execture block in floating seconds. | |
+ | |
+ $ perl -Mojo -E 'say i { say g("mojolicio.us")->code }' | |
+ | |
=head2 j | |
my $bytes = j([1, 2, 3]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment