snipt

Ctrl+h for KB shortcuts

Perl

calculate elapsed time (in ms) in Perl code

1
2
3
4
5
use Time::HiRes;

my $t_start = [Time::HiRes::gettimeofday];
my $t_end = [Time::HiRes::gettimeofday];
print Time::HiRes::tv_interval ($t_start, $t_end) . "\n";
https://snipt.net/embed/a8fafdd82bee992cfa9efc11737e4019/
/raw/a8fafdd82bee992cfa9efc11737e4019/
a8fafdd82bee992cfa9efc11737e4019
perl
Perl
5
2019-05-24T13:18:53
True
False
False
/api/public/snipt/3772/
calculate-elapsed-time-in-ms-in-perl-code
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="k">use</span> <span class="nn">Time::</span><span class="n">HiRes</span><span class="p">;</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="k">my</span> <span class="nv">$t_start</span> <span class="o">=</span> <span class="p">[</span><span class="nn">Time::HiRes::</span><span class="n">gettimeofday</span><span class="p">];</span> </span><span id="L-4"><a name="L-4"></a><span class="k">my</span> <span class="nv">$t_end</span> <span class="o">=</span> <span class="p">[</span><span class="nn">Time::HiRes::</span><span class="n">gettimeofday</span><span class="p">];</span> </span><span id="L-5"><a name="L-5"></a><span class="k">print</span> <span class="nn">Time::HiRes::</span><span class="n">tv_interval</span> <span class="p">(</span><span class="nv">$t_start</span><span class="p">,</span> <span class="nv">$t_end</span><span class="p">)</span> <span class="o">.</span> <span class="s">&quot;\n&quot;</span><span class="p">;</span> </span></pre></div> </td></tr></table>
hires, perl, time