As long as we're all tweaking the heck out of our benchmarks... ;-)

What I've noticed is the number of calls to these functions are not all the same. In the 'interval' function, we are calling gettimeofday, constructing an anonymous array, calling tv_interval, and destroying the array. Only one of these are we actually interested in. Meanwhile, both of the other two cases, we're calling *time twice. A completely different set of comparisons. I also eliminated the overhead of returning floats, what little that should be.

So, I thought I'd throw this into the mix. Put all the initialisation up front. Then see what happens.

#! /usr/bin/perl use warnings; use strict; use Time::HiRes qw(time); use Benchmark qw(:all) ; my $interval0 = [Time::HiRes::gettimeofday()]; my $hires0 = Time::HiRes::time(); my $time0 = time(); cmpthese(-1, { 'interval' => sub { my $elapsed = Time::HiRes::tv_interval($interval0); return; }, 'hires' => sub { my $elapsed = Time::HiRes::time() - $hires0; return; }, 'time' => sub { my $elapsed = time - $time0; return; }, });
And the results?
Rate interval time hires interval 685148/s -- -79% -80% time 3340426/s 388% -- -2% hires 3398163/s 396% 2% --
2% bonus to hires's time over the built-in time? I'll chalk that up to statistically insignificant, and call the two a tie. In fact, I ran it a second time and got it reversed:
Rate interval hires time interval 971246/s -- -77% -78% hires 4192706/s 332% -- -3% time 4327848/s 346% 3% --
So, I'd say that the difference between interval and time is non-trivial. But even that operates fast enough that I'm not going to worry about it.


In reply to Re^4: Measuring time intervals using Time::HiRes -- time vs. gettimeofday and tv_interval by Tanktalus
in thread Measuring time intervals using Time::HiRes -- time vs. gettimeofday and tv_interval by hrr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.