snipt

Ctrl+h for KB shortcuts

JavaScript

JS: Simple benchmark between two slices of code

1
2
3
4
5
6
var start = +new Date();

// Here the code I want to benchmark

var end = +new Date();
console.log((end - start) + " ms");
https://snippets.siftie.com/embed/81e89730ab287f6db2672c73aaf4f28b/
/raw/81e89730ab287f6db2672c73aaf4f28b/
81e89730ab287f6db2672c73aaf4f28b
js
JavaScript
6
2016-12-20T05:29:18
True
False
True
Dec 16, 2012 at 07:11 PM
/api/public/snipt/51925/
js-simple-benchmark-between-two-slices-of-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> <a href="#L-6">6</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="kd">var</span> <span class="nx">start</span> <span class="o">=</span> <span class="o">+</span><span class="k">new</span> <span class="nb">Date</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="c1">// Here the code I want to benchmark</span> </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a><span class="kd">var</span> <span class="nx">end</span> <span class="o">=</span> <span class="o">+</span><span class="k">new</span> <span class="nb">Date</span><span class="p">();</span> </span><span id="L-6"><a name="L-6"></a><span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">((</span><span class="nx">end</span> <span class="o">-</span> <span class="nx">start</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot; ms&quot;</span><span class="p">);</span> </span></pre></div> </td></tr></table>
benchmark, js