<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="Deno.bench(function a() {

});

Deno.bench(function b() {
});"><pre class="notranslate"><span class="pl-v">Deno</span><span class="pl-kos">.</span><span class="pl-en">bench</span><span class="pl-kos">(</span><span class="pl-k">function</span> <span class="pl-en">a</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>

<span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

<span class="pl-v">Deno</span><span class="pl-kos">.</span><span class="pl-en">bench</span><span class="pl-kos">(</span><span class="pl-k">function</span> <span class="pl-en">b</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="xxx@xxx xxx % deno bench
Check file:///Users/xxx/WebstormProjects/radash/main_bench.ts
cpu: Apple M1 Pro
runtime: deno 1.29.1 (aarch64-apple-darwin)

file:///Users/xxx/WebstormProjects/xxx/main_bench.ts
benchmark      time (avg)             (min … max)       p75       p99      p995
------------------------------------------------- -----------------------------
a          504.73 ps/iter   (458.3 ps … 10.54 ns)    500 ps  654.2 ps   1.22 ns
b             4.2 ns/iter    (4.08 ns … 16.21 ns)   4.23 ns   4.99 ns   7.39 ns"><pre class="notranslate"><code class="notranslate">xxx@xxx xxx % deno bench
Check file:///Users/xxx/WebstormProjects/radash/main_bench.ts
cpu: Apple M1 Pro
runtime: deno 1.29.1 (aarch64-apple-darwin)

file:///Users/xxx/WebstormProjects/xxx/main_bench.ts
benchmark      time (avg)             (min … max)       p75       p99      p995
------------------------------------------------- -----------------------------
a          504.73 ps/iter   (458.3 ps … 10.54 ns)    500 ps  654.2 ps   1.22 ns
b             4.2 ns/iter    (4.08 ns … 16.21 ns)   4.23 ns   4.99 ns   7.39 ns
</code></pre></div>
<p dir="auto">After adding the same code into a and b.</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import { draw } from 'npm:radash';

Deno.bench(function a() {
    draw(['test', '123', 'fff', 'ggg']);
});

Deno.bench(function b() {
    draw(['test', '123', 'fff', 'ggg']);
});"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-kos">{</span> <span class="pl-s1">draw</span> <span class="pl-kos">}</span> <span class="pl-k">from</span> <span class="pl-s">'npm:radash'</span><span class="pl-kos">;</span>

<span class="pl-v">Deno</span><span class="pl-kos">.</span><span class="pl-en">bench</span><span class="pl-kos">(</span><span class="pl-k">function</span> <span class="pl-en">a</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-en">draw</span><span class="pl-kos">(</span><span class="pl-kos">[</span><span class="pl-s">'test'</span><span class="pl-kos">,</span> <span class="pl-s">'123'</span><span class="pl-kos">,</span> <span class="pl-s">'fff'</span><span class="pl-kos">,</span> <span class="pl-s">'ggg'</span><span class="pl-kos">]</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

<span class="pl-v">Deno</span><span class="pl-kos">.</span><span class="pl-en">bench</span><span class="pl-kos">(</span><span class="pl-k">function</span> <span class="pl-en">b</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-en">draw</span><span class="pl-kos">(</span><span class="pl-kos">[</span><span class="pl-s">'test'</span><span class="pl-kos">,</span> <span class="pl-s">'123'</span><span class="pl-kos">,</span> <span class="pl-s">'fff'</span><span class="pl-kos">,</span> <span class="pl-s">'ggg'</span><span class="pl-kos">]</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="xxx@xxx xxx % deno bench
Check file:///Users/xxx/WebstormProjects/xxx/main_bench.ts
cpu: Apple M1 Pro
runtime: deno 1.29.1 (aarch64-apple-darwin)

file:///Users/xxx/WebstormProjects/xxx/main_bench.ts
benchmark      time (avg)             (min … max)       p75       p99      p995
------------------------------------------------- -----------------------------
a            7.56 ns/iter     (6.8 ns … 92.49 ns)   7.48 ns  14.83 ns  16.84 ns
b           27.21 ns/iter    (24.8 ns … 64.18 ns)  27.06 ns  42.39 ns  44.32 ns"><pre class="notranslate"><code class="notranslate">xxx@xxx xxx % deno bench
Check file:///Users/xxx/WebstormProjects/xxx/main_bench.ts
cpu: Apple M1 Pro
runtime: deno 1.29.1 (aarch64-apple-darwin)

file:///Users/xxx/WebstormProjects/xxx/main_bench.ts
benchmark      time (avg)             (min … max)       p75       p99      p995
------------------------------------------------- -----------------------------
a            7.56 ns/iter     (6.8 ns … 92.49 ns)   7.48 ns  14.83 ns  16.84 ns
b           27.21 ns/iter    (24.8 ns … 64.18 ns)  27.06 ns  42.39 ns  44.32 ns
</code></pre></div>
<p dir="auto">Hello,</p>
<p dir="auto">I've a behavior in Deno.bench that I cannot explain :</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="Deno.bench(&quot;noop&quot;, () =&gt; {});
Deno.bench(&quot;noop&quot;, () =&gt; {});
Deno.bench(&quot;noop&quot;, () =&gt; {});"><pre class="notranslate"><span class="pl-smi">Deno</span><span class="pl-kos">.</span><span class="pl-en">bench</span><span class="pl-kos">(</span><span class="pl-s">"noop"</span><span class="pl-kos">,</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span><span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-smi">Deno</span><span class="pl-kos">.</span><span class="pl-en">bench</span><span class="pl-kos">(</span><span class="pl-s">"noop"</span><span class="pl-kos">,</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span><span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-smi">Deno</span><span class="pl-kos">.</span><span class="pl-en">bench</span><span class="pl-kos">(</span><span class="pl-s">"noop"</span><span class="pl-kos">,</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span><span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="❯ deno bench --unstable noop.ts
cpu: Apple M1
runtime: deno 1.23.3 (aarch64-apple-darwin)

benchmark      time (avg)             (min … max)       p75       p99      p995
------------------------------------------------- -----------------------------
noop       490.06 ps/iter   (466.6 ps … 47.63 ns)  479.2 ps  516.7 ps  529.1 ps
noop         4.29 ns/iter    (4.12 ns … 32.86 ns)   4.22 ns   4.67 ns   5.38 ns
noop         4.22 ns/iter    (4.12 ns … 33.54 ns)   4.23 ns   4.58 ns   4.79 ns"><pre class="notranslate">❯ deno bench --unstable noop.ts
cpu: Apple M1
runtime: deno 1.23.3 (aarch64-apple-darwin)

benchmark      <span class="pl-k">time</span> (avg)             (min … max)       p75       p99      p995
------------------------------------------------- -----------------------------
noop       490.06 ps/iter   (466.6 ps … 47.63 ns)  479.2 ps  516.7 ps  529.1 ps
noop         4.29 ns/iter    (4.12 ns … 32.86 ns)   4.22 ns   4.67 ns   5.38 ns
noop         4.22 ns/iter    (4.12 ns … 33.54 ns)   4.23 ns   4.58 ns   4.79 ns</pre></div>
<p dir="auto">Easy to say that second and third results are close and are explained by CPU activity, but why the first is ~10x faster ?<br>
Maybe something like "reset" job between them, that are not executed for the first, but, in this case, is it possible to execute this "reset" before the first job too, to be consistent ? Or just don't monitor them ?</p>
<p dir="auto">Best regards,<br>
Gaël</p>