Created
September 9, 2013 22:01
-
-
Save dtjm/6502122 to your computer and use it in GitHub Desktop.
AnyEvent->time vs Time::HiRes::time
This file contains hidden or 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
| use strict; | |
| use AnyEvent; | |
| use Time::HiRes; | |
| use Data::Dumper; | |
| my $iterations = 10000000; | |
| my $start = Time::HiRes::time; | |
| for ( my $i = 0; $i < $iterations; $i++ ) | |
| { | |
| AnyEvent->time; | |
| } | |
| my $total = Time::HiRes::time - $start; | |
| print "$iterations iterations of AnyEvent->time in $total s\n"; | |
| $start = Time::HiRes::time; | |
| for ( my $i = 0; $i < $iterations; $i++ ) | |
| { | |
| Time::HiRes::time; | |
| } | |
| $total = Time::HiRes::time - $start; | |
| print "$iterations iterations of Time::HiRes::time in $total s\n"; | |
| my $sum = 0.0; | |
| for ( my $i = 0; $i < $iterations; $i++ ) | |
| { | |
| my $time = Time::HiRes::time * 1000; | |
| my $anyEvent = AnyEvent->time * 1000; | |
| $sum += ($anyEvent - $time); | |
| } | |
| my $avgDelta = $sum / $iterations; | |
| print "avg_delta=$avgDelta\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output: