Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: Enhancing Performance and Readability with Switch Statements 🚀 #51304

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sanjaiyan-dev
Copy link
Contributor

Hi, this PR will result in a very minimal performance improvement by changing from multiple if conditions to a switch statement. Since a switch statement utilizes a branch table (correct me if I'm wrong), the gain in performance will be marginal, but it enhances code readability.

I've attached a picture of the JavaScript benchmark I ran, and there's a YouTube video demonstrating how a switch statement can lead to performance gains. The video showcases how the C compiler optimizes switch statements, and if I'm correct, this optimization principle should also apply to the V8 engine, which JIT compiles JavaScript to assembly language: YouTube link.

This is the fixed version (pull request) of #51281

@nodejs-github-bot nodejs-github-bot added buffer Issues and PRs related to the buffer subsystem. needs-ci PRs that need a full CI run. labels Dec 28, 2023
@H4ad
Copy link
Member

H4ad commented Dec 28, 2023

Thanks for the PR, now both changes and the commit message are good!


To evaluate the perf improvement/regression of this change, I will run the following benchmark, I will post the results once it finishes (you probably will not have access to it right now).

Benchmark CI: https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/1488/

This can take multiple minutes/hours to finish, I will decide if I approve if there is no regression.


@nodejs/performance Talking about micro-optimizations, someone has any thoughts on changing the order of case to define more common byteLength first? Like 1, 2 and 3.

@RafaelGSS RafaelGSS added the performance Issues and PRs related to the performance of Node.js. label Dec 28, 2023
@sanjaiyan-dev
Copy link
Contributor Author

@nodejs/performance Talking about micro-optimizations, someone has any thoughts on changing the order of case to define more common byteLength first? Like 1, 2 and 3.

Welcome! By the way, I believe the switch statement uses a branch table, so unlike an if statement, the order doesn't matter. (I'm sorry if I'm mistaken.)

case '[object Float32Array]': return 7;
case '[object Float64Array]': return 8;
case '[object DataView]': return 9;
// Index 10 id FastBuffer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Index 10 id FastBuffer
// Index 10 is FastBuffer
@Uzlopak
Copy link
Contributor

Uzlopak commented Dec 28, 2023

I am confused. I would expect that putting some stuff in an array is faster.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Can you include some benchmark results?

Copy link
Member

@benjamingr benjamingr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please run benchmarks :]

@aduh95
Copy link
Contributor

aduh95 commented Dec 29, 2023

Benchmark CI: https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/1488/

It doesn't look like a clear win

buffers/buffer-fill.js n=20000 size=8192 type='fill("t", "utf8")'                                                                                      ***     -8.34 %       ±2.83%  ±3.77%  ±4.91%
buffers/buffer-read-with-byteLength.js byteLength=1 n=1000000 type='IntBE' buffer='fast'                                                               ***      4.08 %       ±0.66%  ±0.88%  ±1.15%
buffers/buffer-read-with-byteLength.js byteLength=1 n=1000000 type='IntLE' buffer='fast'                                                               ***      4.03 %       ±0.41%  ±0.54%  ±0.71%
buffers/buffer-read-with-byteLength.js byteLength=1 n=1000000 type='UIntBE' buffer='fast'                                                              ***      1.66 %       ±0.47%  ±0.63%  ±0.82%
buffers/buffer-read-with-byteLength.js byteLength=1 n=1000000 type='UIntLE' buffer='fast'                                                              ***      1.62 %       ±0.47%  ±0.63%  ±0.82%
buffers/buffer-read-with-byteLength.js byteLength=3 n=1000000 type='IntBE' buffer='fast'                                                               ***     -2.82 %       ±0.84%  ±1.12%  ±1.46%
buffers/buffer-read-with-byteLength.js byteLength=3 n=1000000 type='IntLE' buffer='fast'                                                               ***     -4.13 %       ±2.31%  ±3.10%  ±4.08%
buffers/buffer-read-with-byteLength.js byteLength=3 n=1000000 type='UIntBE' buffer='fast'                                                              ***     -2.78 %       ±0.78%  ±1.04%  ±1.36%
buffers/buffer-read-with-byteLength.js byteLength=3 n=1000000 type='UIntLE' buffer='fast'                                                              ***     -2.47 %       ±0.85%  ±1.13%  ±1.48%
buffers/buffer-read-with-byteLength.js byteLength=5 n=1000000 type='IntBE' buffer='fast'                                                               ***     -4.13 %       ±0.72%  ±0.96%  ±1.24%
buffers/buffer-read-with-byteLength.js byteLength=5 n=1000000 type='IntLE' buffer='fast'                                                               ***     -4.31 %       ±1.24%  ±1.66%  ±2.18%
buffers/buffer-read-with-byteLength.js byteLength=5 n=1000000 type='UIntBE' buffer='fast'                                                              ***     -4.70 %       ±1.13%  ±1.51%  ±1.99%
buffers/buffer-read-with-byteLength.js byteLength=6 n=1000000 type='IntBE' buffer='fast'                                                               ***     -8.47 %       ±2.58%  ±3.47%  ±4.60%
buffers/buffer-read-with-byteLength.js byteLength=6 n=1000000 type='IntLE' buffer='fast'                                                               ***     -7.86 %       ±2.25%  ±3.02%  ±3.99%
buffers/buffer-read-with-byteLength.js byteLength=6 n=1000000 type='UIntBE' buffer='fast'                                                              ***     -7.07 %       ±3.48%  ±4.63%  ±6.02%
buffers/buffer-read-with-byteLength.js byteLength=6 n=1000000 type='UIntLE' buffer='fast'                                                              ***     -8.28 %       ±2.50%  ±3.34%  ±4.40%
confidence improvement accuracy (*)    (**)   (***)
buffers/buffer-base64-decode-wrapped.js n=32 linesCount=524288 charsPerLine=76                                                                                 -0.46 %       ±0.75%  ±1.00%  ±1.30%
buffers/buffer-base64-decode.js size=8388608 n=32                                                                                                              -0.13 %       ±1.04%  ±1.39%  ±1.81%
buffers/buffer-base64-encode.js n=32 len=67108864                                                                                                              -0.40 %       ±0.86%  ±1.15%  ±1.49%
buffers/buffer-base64url-decode.js size=8388608 n=32                                                                                                           -0.06 %       ±1.14%  ±1.52%  ±1.98%
buffers/buffer-base64url-encode.js n=32 len=67108864                                                                                                            0.27 %       ±0.60%  ±0.80%  ±1.04%
buffers/buffer-bytelength-buffer.js n=4000000 len=16                                                                                                           -0.30 %       ±9.60% ±12.77% ±16.62%
buffers/buffer-bytelength-buffer.js n=4000000 len=2                                                                                                             3.13 %       ±7.32%  ±9.78% ±12.83%
buffers/buffer-bytelength-buffer.js n=4000000 len=256                                                                                                    *     11.52 %       ±9.59% ±12.76% ±16.61%
buffers/buffer-bytelength-string.js n=4000000 repeat=1 encoding='base64' type='four_bytes'                                                                     -0.40 %       ±5.01%  ±6.67%  ±8.68%
buffers/buffer-bytelength-string.js n=4000000 repeat=1 encoding='base64' type='latin1'                                                                          3.02 %       ±5.79%  ±7.71% ±10.04%
buffers/buffer-bytelength-string.js n=4000000 repeat=1 encoding='base64' type='one_byte'                                                                       -1.74 %       ±5.38%  ±7.16%  ±9.32%
buffers/buffer-bytelength-string.js n=4000000 repeat=1 encoding='base64' type='three_bytes'                                                                     3.59 %       ±6.01%  ±7.99% ±10.40%
buffers/buffer-bytelength-string.js n=4000000 repeat=1 encoding='base64' type='two_bytes'                                                                       1.08 %       ±5.14%  ±6.84%  ±8.90%
buffers/buffer-bytelength-string.js n=4000000 repeat=1 encoding='utf8' type='four_bytes'                                                                        0.18 %       ±2.69%  ±3.58%  ±4.66%
buffers/buffer-bytelength-string.js n=4000000 repeat=1 encoding='utf8' type='latin1'                                                                            1.86 %       ±3.31%  ±4.41%  ±5.76%
buffers/buffer-bytelength-string.js n=4000000 repeat=1 encoding='utf8' type='one_byte'                                                                         -0.78 %       ±7.50%  ±9.99% ±13.01%
buffers/buffer-bytelength-string.js n=4000000 repeat=1 encoding='utf8' type='three_bytes'                                                                      -0.62 %       ±3.39%  ±4.51%  ±5.87%
buffers/buffer-bytelength-string.js n=4000000 repeat=1 encoding='utf8' type='two_bytes'                                                                        -0.41 %       ±3.60%  ±4.79%  ±6.23%
buffers/buffer-bytelength-string.js n=4000000 repeat=16 encoding='base64' type='four_bytes'                                                                    -1.53 %       ±4.35%  ±5.79%  ±7.53%
buffers/buffer-bytelength-string.js n=4000000 repeat=16 encoding='base64' type='latin1'                                                                  *      5.22 %       ±4.82%  ±6.42%  ±8.38%
buffers/buffer-bytelength-string.js n=4000000 repeat=16 encoding='base64' type='one_byte'                                                                       0.08 %       ±4.90%  ±6.52%  ±8.49%
buffers/buffer-bytelength-string.js n=4000000 repeat=16 encoding='base64' type='three_bytes'                                                             *      6.06 %       ±5.18%  ±6.89%  ±8.98%
buffers/buffer-bytelength-string.js n=4000000 repeat=16 encoding='base64' type='two_bytes'                                                                      2.72 %       ±5.33%  ±7.09%  ±9.24%
buffers/buffer-bytelength-string.js n=4000000 repeat=16 encoding='utf8' type='four_bytes'                                                                      -0.15 %       ±0.59%  ±0.79%  ±1.03%
buffers/buffer-bytelength-string.js n=4000000 repeat=16 encoding='utf8' type='latin1'                                                                          -0.58 %       ±0.69%  ±0.93%  ±1.21%
buffers/buffer-bytelength-string.js n=4000000 repeat=16 encoding='utf8' type='one_byte'                                                                        -0.64 %       ±3.58%  ±4.76%  ±6.20%
buffers/buffer-bytelength-string.js n=4000000 repeat=16 encoding='utf8' type='three_bytes'                                                                     -0.29 %       ±1.31%  ±1.74%  ±2.26%
buffers/buffer-bytelength-string.js n=4000000 repeat=16 encoding='utf8' type='two_bytes'                                                                       -0.21 %       ±1.10%  ±1.47%  ±1.92%
buffers/buffer-bytelength-string.js n=4000000 repeat=2 encoding='base64' type='four_bytes'                                                                     -1.64 %       ±6.06%  ±8.07% ±10.51%
buffers/buffer-bytelength-string.js n=4000000 repeat=2 encoding='base64' type='latin1'                                                                         -2.53 %       ±5.21%  ±6.94%  ±9.03%
buffers/buffer-bytelength-string.js n=4000000 repeat=2 encoding='base64' type='one_byte'                                                                        4.74 %       ±5.15%  ±6.86%  ±8.94%
buffers/buffer-bytelength-string.js n=4000000 repeat=2 encoding='base64' type='three_bytes'                                                              *     -5.09 %       ±4.82%  ±6.42%  ±8.36%
buffers/buffer-bytelength-string.js n=4000000 repeat=2 encoding='base64' type='two_bytes'                                                                       1.86 %       ±5.51%  ±7.33%  ±9.54%
buffers/buffer-bytelength-string.js n=4000000 repeat=2 encoding='utf8' type='four_bytes'                                                                        1.33 %       ±1.40%  ±1.87%  ±2.43%
buffers/buffer-bytelength-string.js n=4000000 repeat=2 encoding='utf8' type='latin1'                                                                            0.77 %       ±2.30%  ±3.07%  ±3.99%
buffers/buffer-bytelength-string.js n=4000000 repeat=2 encoding='utf8' type='one_byte'                                                                         -1.30 %       ±5.35%  ±7.12%  ±9.27%
buffers/buffer-bytelength-string.js n=4000000 repeat=2 encoding='utf8' type='three_bytes'                                                                      -1.23 %       ±2.40%  ±3.20%  ±4.17%
buffers/buffer-bytelength-string.js n=4000000 repeat=2 encoding='utf8' type='two_bytes'                                                                        -0.04 %       ±3.61%  ±4.81%  ±6.26%
buffers/buffer-bytelength-string.js n=4000000 repeat=256 encoding='base64' type='four_bytes'                                                                    3.54 %       ±5.74%  ±7.64%  ±9.95%
buffers/buffer-bytelength-string.js n=4000000 repeat=256 encoding='base64' type='latin1'                                                                       -0.02 %       ±5.09%  ±6.77%  ±8.82%
buffers/buffer-bytelength-string.js n=4000000 repeat=256 encoding='base64' type='one_byte'                                                                      1.58 %       ±4.85%  ±6.45%  ±8.39%
buffers/buffer-bytelength-string.js n=4000000 repeat=256 encoding='base64' type='three_bytes'                                                                  -1.48 %       ±4.60%  ±6.12%  ±7.97%
buffers/buffer-bytelength-string.js n=4000000 repeat=256 encoding='base64' type='two_bytes'                                                                    -1.41 %       ±5.84%  ±7.78% ±10.13%
buffers/buffer-bytelength-string.js n=4000000 repeat=256 encoding='utf8' type='four_bytes'                                                                     -0.00 %       ±0.05%  ±0.06%  ±0.08%
buffers/buffer-bytelength-string.js n=4000000 repeat=256 encoding='utf8' type='latin1'                                                                          0.06 %       ±0.19%  ±0.25%  ±0.32%
buffers/buffer-bytelength-string.js n=4000000 repeat=256 encoding='utf8' type='one_byte'                                                                        0.12 %       ±0.59%  ±0.79%  ±1.03%
buffers/buffer-bytelength-string.js n=4000000 repeat=256 encoding='utf8' type='three_bytes'                                                                    -0.10 %       ±0.15%  ±0.20%  ±0.26%
buffers/buffer-bytelength-string.js n=4000000 repeat=256 encoding='utf8' type='two_bytes'                                                                       0.03 %       ±0.12%  ±0.16%  ±0.22%
buffers/buffer-compare-instance-method.js n=1000000 args=1 size=16                                                                                             -0.47 %       ±6.63%  ±8.85% ±11.55%
buffers/buffer-compare-instance-method.js n=1000000 args=1 size=16386                                                                                          -0.79 %       ±2.56%  ±3.40%  ±4.43%
buffers/buffer-compare-instance-method.js n=1000000 args=1 size=4096                                                                                            4.62 %       ±8.20% ±10.92% ±14.21%
buffers/buffer-compare-instance-method.js n=1000000 args=1 size=512                                                                                             1.55 %      ±10.29% ±13.70% ±17.83%
buffers/buffer-compare-instance-method.js n=1000000 args=2 size=16                                                                                              2.62 %       ±9.04% ±12.03% ±15.67%
buffers/buffer-compare-instance-method.js n=1000000 args=2 size=16386                                                                                          -0.05 %       ±2.59%  ±3.45%  ±4.49%
buffers/buffer-compare-instance-method.js n=1000000 args=2 size=4096                                                                                            1.44 %       ±5.87%  ±7.82% ±10.19%
buffers/buffer-compare-instance-method.js n=1000000 args=2 size=512                                                                                            -5.06 %       ±8.39% ±11.16% ±14.53%
buffers/buffer-compare-instance-method.js n=1000000 args=5 size=16                                                                                             -5.32 %       ±9.44% ±12.56% ±16.35%
buffers/buffer-compare-instance-method.js n=1000000 args=5 size=16386                                                                                           0.68 %       ±2.32%  ±3.09%  ±4.03%
buffers/buffer-compare-instance-method.js n=1000000 args=5 size=4096                                                                                            1.15 %       ±4.77%  ±6.35%  ±8.27%
buffers/buffer-compare-instance-method.js n=1000000 args=5 size=512                                                                                             2.66 %       ±7.67% ±10.21% ±13.29%
buffers/buffer-compare-offset.js n=1000000 size=16 method='offset'                                                                                             -3.88 %       ±8.59% ±11.43% ±14.87%
buffers/buffer-compare-offset.js n=1000000 size=16 method='slice'                                                                                              -0.99 %       ±3.62%  ±4.81%  ±6.27%
buffers/buffer-compare-offset.js n=1000000 size=16386 method='offset'                                                                                           2.45 %       ±8.56% ±11.38% ±14.82%
buffers/buffer-compare-offset.js n=1000000 size=16386 method='slice'                                                                                            2.10 %       ±3.59%  ±4.77%  ±6.21%
buffers/buffer-compare-offset.js n=1000000 size=4096 method='offset'                                                                                           -1.32 %       ±8.26% ±11.00% ±14.34%
buffers/buffer-compare-offset.js n=1000000 size=4096 method='slice'                                                                                            -1.57 %       ±3.09%  ±4.12%  ±5.36%
buffers/buffer-compare-offset.js n=1000000 size=512 method='offset'                                                                                             4.20 %       ±9.74% ±12.95% ±16.86%
buffers/buffer-compare-offset.js n=1000000 size=512 method='slice'                                                                                             -1.08 %       ±2.44%  ±3.26%  ±4.25%
buffers/buffer-compare.js n=1000000 size=16                                                                                                                    -1.20 %       ±7.32%  ±9.74% ±12.69%
buffers/buffer-compare.js n=1000000 size=16386                                                                                                                 -0.35 %       ±3.27%  ±4.36%  ±5.67%
buffers/buffer-compare.js n=1000000 size=4096                                                                                                           **    -11.62 %       ±7.38%  ±9.82% ±12.79%
buffers/buffer-compare.js n=1000000 size=512                                                                                                                   -2.13 %       ±9.37% ±12.46% ±16.22%
buffers/buffer-concat-fill.js n=800000 extraSize=1                                                                                                             -0.35 %       ±5.21%  ±6.94%  ±9.03%
buffers/buffer-concat-fill.js n=800000 extraSize=1024                                                                                                           0.05 %       ±2.61%  ±3.49%  ±4.55%
buffers/buffer-concat-fill.js n=800000 extraSize=256                                                                                                           -0.81 %       ±3.23%  ±4.30%  ±5.60%
buffers/buffer-concat.js n=800000 withTotalLength=0 pieceSize=1 pieces=16                                                                                       1.40 %       ±3.04%  ±4.04%  ±5.26%
buffers/buffer-concat.js n=800000 withTotalLength=0 pieceSize=1 pieces=4                                                                                        1.32 %       ±8.24% ±10.96% ±14.27%
buffers/buffer-concat.js n=800000 withTotalLength=0 pieceSize=16 pieces=16                                                                                      0.71 %       ±3.20%  ±4.26%  ±5.54%
buffers/buffer-concat.js n=800000 withTotalLength=0 pieceSize=16 pieces=4                                                                                       2.88 %       ±7.80% ±10.38% ±13.52%
buffers/buffer-concat.js n=800000 withTotalLength=0 pieceSize=256 pieces=16                                                                                     0.22 %       ±1.16%  ±1.54%  ±2.01%
buffers/buffer-concat.js n=800000 withTotalLength=0 pieceSize=256 pieces=4                                                                                     -1.41 %       ±3.30%  ±4.40%  ±5.73%
buffers/buffer-concat.js n=800000 withTotalLength=1 pieceSize=1 pieces=16                                                                                       0.54 %       ±2.42%  ±3.22%  ±4.19%
buffers/buffer-concat.js n=800000 withTotalLength=1 pieceSize=1 pieces=4                                                                                        0.18 %       ±7.71% ±10.28% ±13.40%
buffers/buffer-concat.js n=800000 withTotalLength=1 pieceSize=16 pieces=16                                                                                     -1.00 %       ±3.30%  ±4.39%  ±5.72%
buffers/buffer-concat.js n=800000 withTotalLength=1 pieceSize=16 pieces=4                                                                                      -0.83 %       ±7.20%  ±9.59% ±12.48%
buffers/buffer-concat.js n=800000 withTotalLength=1 pieceSize=256 pieces=16                                                                                     0.84 %       ±1.49%  ±1.98%  ±2.57%
buffers/buffer-concat.js n=800000 withTotalLength=1 pieceSize=256 pieces=4                                                                                     -1.10 %       ±3.65%  ±4.85%  ±6.31%
buffers/buffer-copy.js n=6000000 partial='false' bytes=0                                                                                                       -0.28 %       ±5.16%  ±6.87%  ±8.94%
buffers/buffer-copy.js n=6000000 partial='true' bytes=128                                                                                                       0.10 %       ±1.74%  ±2.32%  ±3.02%
buffers/buffer-copy.js n=6000000 partial='true' bytes=32768                                                                                                     0.42 %       ±1.36%  ±1.81%  ±2.36%
buffers/buffer-copy.js n=6000000 partial='true' bytes=8                                                                                                        -0.43 %       ±2.23%  ±2.97%  ±3.87%
buffers/buffer-creation.js n=600000 len=10 type='fast-alloc-fill'                                                                                              -1.41 %       ±9.71% ±12.92% ±16.82%
buffers/buffer-creation.js n=600000 len=10 type='fast-alloc'                                                                                                    1.76 %       ±6.39%  ±8.50% ±11.08%
buffers/buffer-creation.js n=600000 len=10 type='fast-allocUnsafe'                                                                                              1.66 %       ±7.21%  ±9.59% ±12.49%
buffers/buffer-creation.js n=600000 len=10 type='slow-allocUnsafe'                                                                                       *      9.79 %       ±9.31% ±12.41% ±16.19%
buffers/buffer-creation.js n=600000 len=1024 type='fast-alloc-fill'                                                                                             0.35 %       ±1.73%  ±2.31%  ±3.00%
buffers/buffer-creation.js n=600000 len=1024 type='fast-alloc'                                                                                                  0.12 %       ±2.05%  ±2.72%  ±3.55%
buffers/buffer-creation.js n=600000 len=1024 type='fast-allocUnsafe'                                                                                            0.51 %       ±5.11%  ±6.79%  ±8.85%
buffers/buffer-creation.js n=600000 len=1024 type='slow-allocUnsafe'                                                                                            0.81 %       ±2.51%  ±3.34%  ±4.36%
buffers/buffer-creation.js n=600000 len=4096 type='fast-alloc-fill'                                                                                            -0.16 %       ±1.36%  ±1.81%  ±2.35%
buffers/buffer-creation.js n=600000 len=4096 type='fast-alloc'                                                                                                  0.99 %       ±1.60%  ±2.13%  ±2.77%
buffers/buffer-creation.js n=600000 len=4096 type='fast-allocUnsafe'                                                                                           -0.19 %       ±2.29%  ±3.04%  ±3.97%
buffers/buffer-creation.js n=600000 len=4096 type='slow-allocUnsafe'                                                                                           -0.67 %       ±1.92%  ±2.56%  ±3.34%
buffers/buffer-creation.js n=600000 len=8192 type='fast-alloc-fill'                                                                                             0.53 %       ±1.32%  ±1.75%  ±2.28%
buffers/buffer-creation.js n=600000 len=8192 type='fast-alloc'                                                                                                 -0.71 %       ±1.72%  ±2.29%  ±2.98%
buffers/buffer-creation.js n=600000 len=8192 type='fast-allocUnsafe'                                                                                            0.23 %       ±1.73%  ±2.31%  ±3.00%
buffers/buffer-creation.js n=600000 len=8192 type='slow-allocUnsafe'                                                                                           -0.96 %       ±1.94%  ±2.58%  ±3.36%
buffers/buffer-equals.js n=1000000 difflen='false' size=0                                                                                                       2.84 %       ±6.10%  ±8.13% ±10.58%
buffers/buffer-equals.js n=1000000 difflen='false' size=16386                                                                                                   1.22 %       ±3.25%  ±4.32%  ±5.62%
buffers/buffer-equals.js n=1000000 difflen='false' size=512                                                                                              *     11.90 %       ±9.50% ±12.73% ±16.75%
buffers/buffer-equals.js n=1000000 difflen='true' size=0                                                                                                       -0.05 %       ±3.13%  ±4.17%  ±5.42%
buffers/buffer-equals.js n=1000000 difflen='true' size=16386                                                                                                    2.06 %       ±8.71% ±11.59% ±15.09%
buffers/buffer-equals.js n=1000000 difflen='true' size=512                                                                                                      0.99 %       ±6.16%  ±8.20% ±10.68%
buffers/buffer-fill.js n=20000 size=65536 type='fill("")'                                                                                                       0.13 %       ±3.51%  ±4.67%  ±6.10%
buffers/buffer-fill.js n=20000 size=65536 type='fill("t", "utf8")'                                                                                             -0.34 %       ±1.52%  ±2.03%  ±2.64%
buffers/buffer-fill.js n=20000 size=65536 type='fill("t", 0, "utf8")'                                                                                           0.39 %       ±1.55%  ±2.07%  ±2.69%
buffers/buffer-fill.js n=20000 size=65536 type='fill("t", 0)'                                                                                                  -1.19 %       ±2.72%  ±3.64%  ±4.77%
buffers/buffer-fill.js n=20000 size=65536 type='fill("t")'                                                                                                     -2.22 %       ±3.10%  ±4.16%  ±5.48%
buffers/buffer-fill.js n=20000 size=65536 type='fill("test")'                                                                                                  -1.51 %       ±3.34%  ±4.49%  ±5.96%
buffers/buffer-fill.js n=20000 size=65536 type='fill(0)'                                                                                                        0.63 %       ±1.80%  ±2.40%  ±3.12%
buffers/buffer-fill.js n=20000 size=65536 type='fill(100)'                                                                                                      1.69 %       ±3.79%  ±5.09%  ±6.72%
buffers/buffer-fill.js n=20000 size=65536 type='fill(400)'                                                                                                      0.02 %       ±1.75%  ±2.34%  ±3.04%
buffers/buffer-fill.js n=20000 size=65536 type='fill(Buffer.alloc(1), 0)'                                                                                      -1.23 %       ±3.01%  ±4.04%  ±5.35%
buffers/buffer-fill.js n=20000 size=8192 type='fill("")'                                                                                                       -1.62 %       ±2.33%  ±3.11%  ±4.06%
buffers/buffer-fill.js n=20000 size=8192 type='fill("t", "utf8")'                                                                                      ***     -8.34 %       ±2.83%  ±3.77%  ±4.91%
buffers/buffer-fill.js n=20000 size=8192 type='fill("t", 0, "utf8")'                                                                                           -0.77 %       ±2.81%  ±3.74%  ±4.87%
buffers/buffer-fill.js n=20000 size=8192 type='fill("t", 0)'                                                                                             *     -3.98 %       ±3.69%  ±4.92%  ±6.40%
buffers/buffer-fill.js n=20000 size=8192 type='fill("t")'                                                                                                      -1.89 %       ±2.34%  ±3.12%  ±4.06%
buffers/buffer-fill.js n=20000 size=8192 type='fill("test")'                                                                                            **     -3.07 %       ±2.23%  ±2.98%  ±3.89%
buffers/buffer-fill.js n=20000 size=8192 type='fill(0)'                                                                                                        -0.07 %       ±3.63%  ±4.83%  ±6.28%
buffers/buffer-fill.js n=20000 size=8192 type='fill(100)'                                                                                                      -2.03 %       ±3.26%  ±4.34%  ±5.65%
buffers/buffer-fill.js n=20000 size=8192 type='fill(400)'                                                                                                       1.45 %       ±3.57%  ±4.76%  ±6.19%
buffers/buffer-fill.js n=20000 size=8192 type='fill(Buffer.alloc(1), 0)'                                                                                       -1.53 %       ±3.12%  ±4.16%  ±5.43%
buffers/buffer-from.js n=800000 len=100 source='array'                                                                                                          2.59 %       ±6.53%  ±8.69% ±11.32%
buffers/buffer-from.js n=800000 len=100 source='arraybuffer-middle'                                                                                             6.75 %      ±10.89% ±14.49% ±18.86%
buffers/buffer-from.js n=800000 len=100 source='arraybuffer'                                                                                                    1.57 %      ±10.15% ±13.50% ±17.57%
buffers/buffer-from.js n=800000 len=100 source='buffer'                                                                                                         0.33 %       ±8.41% ±11.19% ±14.57%
buffers/buffer-from.js n=800000 len=100 source='object'                                                                                                         1.96 %      ±10.39% ±13.82% ±17.99%
buffers/buffer-from.js n=800000 len=100 source='string-base64'                                                                                                 -2.63 %       ±4.91%  ±6.53%  ±8.51%
buffers/buffer-from.js n=800000 len=100 source='string-utf8'                                                                                                    1.90 %       ±6.59%  ±8.77% ±11.42%
buffers/buffer-from.js n=800000 len=100 source='string'                                                                                                         2.95 %       ±5.98%  ±7.95% ±10.35%
buffers/buffer-from.js n=800000 len=100 source='uint16array'                                                                                                    3.73 %       ±7.74% ±10.29% ±13.40%
buffers/buffer-from.js n=800000 len=100 source='uint8array'                                                                                                     0.36 %       ±8.63% ±11.48% ±14.95%
buffers/buffer-from.js n=800000 len=2048 source='array'                                                                                                        -0.24 %       ±1.10%  ±1.46%  ±1.91%
buffers/buffer-from.js n=800000 len=2048 source='arraybuffer-middle'                                                                                           -4.62 %      ±10.17% ±13.54% ±17.62%
buffers/buffer-from.js n=800000 len=2048 source='arraybuffer'                                                                                                  -5.64 %      ±10.17% ±13.53% ±17.61%
buffers/buffer-from.js n=800000 len=2048 source='buffer'                                                                                                       -0.81 %       ±2.14%  ±2.85%  ±3.71%
buffers/buffer-from.js n=800000 len=2048 source='object'                                                                                                        1.74 %      ±10.40% ±13.84% ±18.02%
buffers/buffer-from.js n=800000 len=2048 source='string-base64'                                                                                                 0.35 %       ±0.93%  ±1.24%  ±1.61%
buffers/buffer-from.js n=800000 len=2048 source='string-utf8'                                                                                                   0.66 %       ±2.00%  ±2.66%  ±3.47%
buffers/buffer-from.js n=800000 len=2048 source='string'                                                                                                       -0.27 %       ±2.23%  ±2.97%  ±3.87%
buffers/buffer-from.js n=800000 len=2048 source='uint16array'                                                                                                  -1.88 %       ±2.26%  ±3.01%  ±3.92%
buffers/buffer-from.js n=800000 len=2048 source='uint8array'                                                                                                    0.32 %       ±2.12%  ±2.82%  ±3.67%
buffers/buffer-hex-decode.js n=1000000 len=1024                                                                                                                 0.34 %       ±0.74%  ±0.99%  ±1.30%
buffers/buffer-hex-decode.js n=1000000 len=64                                                                                                                  -0.99 %       ±3.92%  ±5.21%  ±6.79%
buffers/buffer-hex-encode.js n=1000000 len=1024                                                                                                                -0.77 %       ±0.96%  ±1.27%  ±1.66%
buffers/buffer-hex-encode.js n=1000000 len=64                                                                                                                   0.75 %       ±4.81%  ±6.41%  ±8.36%
buffers/buffer-indexof-number.js n=1000000 value=64                                                                                                            -5.10 %       ±8.05% ±10.74% ±14.02%
buffers/buffer-indexof.js n=50000 type='buffer' encoding='undefined' search='--l'                                                                              -0.30 %       ±6.14%  ±8.18% ±10.64%
buffers/buffer-indexof.js n=50000 type='buffer' encoding='undefined' search='@'                                                                                -0.78 %       ±3.38%  ±4.51%  ±5.89%
buffers/buffer-indexof.js n=50000 type='buffer' encoding='undefined' search='</i> to the Caterpillar'                                                          -0.32 %       ±1.21%  ±1.61%  ±2.09%
buffers/buffer-indexof.js n=50000 type='buffer' encoding='undefined' search='aaaaaaaaaaaaaaaaa'                                                                -0.84 %       ±1.55%  ±2.06%  ±2.69%
buffers/buffer-indexof.js n=50000 type='buffer' encoding='undefined' search='Alice'                                                                            -3.91 %       ±5.35%  ±7.11%  ±9.26%
buffers/buffer-indexof.js n=50000 type='buffer' encoding='undefined' search='found it very'                                                                     0.23 %       ±0.73%  ±0.98%  ±1.27%
buffers/buffer-indexof.js n=50000 type='buffer' encoding='undefined' search='Gryphon'                                                                          -5.90 %       ±9.37% ±12.47% ±16.23%
buffers/buffer-indexof.js n=50000 type='buffer' encoding='undefined' search='neighbouring pool'                                                          *      0.91 %       ±0.80%  ±1.07%  ±1.39%
buffers/buffer-indexof.js n=50000 type='buffer' encoding='undefined' search='Ou est ma chatte?'                                                                -1.07 %       ±2.62%  ±3.49%  ±4.54%
buffers/buffer-indexof.js n=50000 type='buffer' encoding='undefined' search='SQ'                                                                                0.18 %       ±7.96% ±10.59% ±13.78%
buffers/buffer-indexof.js n=50000 type='buffer' encoding='undefined' search='venture to go near the house till she had brought herself down to'                 1.12 %       ±1.80%  ±2.39%  ±3.12%
buffers/buffer-indexof.js n=50000 type='string' encoding='ucs2' search='--l'                                                                                   -0.04 %       ±2.99%  ±3.98%  ±5.19%
buffers/buffer-indexof.js n=50000 type='string' encoding='ucs2' search='@'                                                                                     -1.06 %       ±5.29%  ±7.04%  ±9.16%
buffers/buffer-indexof.js n=50000 type='string' encoding='ucs2' search='</i> to the Caterpillar'                                                               -0.24 %       ±1.43%  ±1.90%  ±2.48%
buffers/buffer-indexof.js n=50000 type='string' encoding='ucs2' search='aaaaaaaaaaaaaaaaa'                                                                     -0.60 %       ±2.33%  ±3.11%  ±4.05%
buffers/buffer-indexof.js n=50000 type='string' encoding='ucs2' search='Alice'                                                                                 -0.14 %       ±8.06% ±10.73% ±13.96%
buffers/buffer-indexof.js n=50000 type='string' encoding='ucs2' search='found it very'                                                                          0.27 %       ±1.14%  ±1.52%  ±1.98%
buffers/buffer-indexof.js n=50000 type='string' encoding='ucs2' search='Gryphon'                                                                               -1.67 %       ±5.01%  ±6.66%  ±8.68%
buffers/buffer-indexof.js n=50000 type='string' encoding='ucs2' search='neighbouring pool'                                                                     -0.58 %       ±1.13%  ±1.51%  ±1.97%
buffers/buffer-indexof.js n=50000 type='string' encoding='ucs2' search='Ou est ma chatte?'                                                               *      2.75 %       ±2.45%  ±3.27%  ±4.25%
buffers/buffer-indexof.js n=50000 type='string' encoding='ucs2' search='SQ'                                                                                     4.00 %       ±9.35% ±12.44% ±16.19%
buffers/buffer-indexof.js n=50000 type='string' encoding='ucs2' search='venture to go near the house till she had brought herself down to'                     -0.59 %       ±1.42%  ±1.89%  ±2.46%
buffers/buffer-indexof.js n=50000 type='string' encoding='utf8' search='--l'                                                                                    4.77 %       ±5.42%  ±7.21%  ±9.39%
buffers/buffer-indexof.js n=50000 type='string' encoding='utf8' search='@'                                                                                      1.25 %       ±4.69%  ±6.26%  ±8.18%
buffers/buffer-indexof.js n=50000 type='string' encoding='utf8' search='</i> to the Caterpillar'                                                                0.32 %       ±1.06%  ±1.41%  ±1.84%
buffers/buffer-indexof.js n=50000 type='string' encoding='utf8' search='aaaaaaaaaaaaaaaaa'                                                                      1.50 %       ±1.68%  ±2.23%  ±2.91%
buffers/buffer-indexof.js n=50000 type='string' encoding='utf8' search='Alice'                                                                                 -3.50 %       ±7.85% ±10.44% ±13.59%
buffers/buffer-indexof.js n=50000 type='string' encoding='utf8' search='found it very'                                                                          0.48 %       ±0.78%  ±1.04%  ±1.36%
buffers/buffer-indexof.js n=50000 type='string' encoding='utf8' search='Gryphon'                                                                                6.89 %       ±9.10% ±12.11% ±15.77%
buffers/buffer-indexof.js n=50000 type='string' encoding='utf8' search='neighbouring pool'                                                                      0.60 %       ±0.91%  ±1.22%  ±1.59%
buffers/buffer-indexof.js n=50000 type='string' encoding='utf8' search='Ou est ma chatte?'                                                                     -0.76 %       ±2.01%  ±2.67%  ±3.47%
buffers/buffer-indexof.js n=50000 type='string' encoding='utf8' search='SQ'                                                                                     2.99 %       ±8.31% ±11.06% ±14.40%
buffers/buffer-indexof.js n=50000 type='string' encoding='utf8' search='venture to go near the house till she had brought herself down to'                     -0.19 %       ±1.53%  ±2.03%  ±2.64%
buffers/buffer-iterate.js n=1000 method='for' type='fast' size=16386                                                                                            2.40 %       ±5.45%  ±7.27%  ±9.51%
buffers/buffer-iterate.js n=1000 method='for' type='fast' size=4096                                                                                            -2.39 %       ±4.98%  ±6.64%  ±8.65%
buffers/buffer-iterate.js n=1000 method='for' type='fast' size=512                                                                                             -2.20 %       ±2.98%  ±3.97%  ±5.17%
buffers/buffer-iterate.js n=1000 method='forOf' type='fast' size=16386                                                                                         -1.09 %       ±7.32%  ±9.74% ±12.67%
buffers/buffer-iterate.js n=1000 method='forOf' type='fast' size=4096                                                                                           1.38 %       ±5.57%  ±7.42%  ±9.67%
buffers/buffer-iterate.js n=1000 method='forOf' type='fast' size=512                                                                                     *      5.13 %       ±4.35%  ±5.81%  ±7.61%
buffers/buffer-iterate.js n=1000 method='iterator' type='fast' size=16386                                                                                       2.35 %       ±7.46%  ±9.93% ±12.93%
buffers/buffer-iterate.js n=1000 method='iterator' type='fast' size=4096                                                                                       -1.65 %       ±5.10%  ±6.79%  ±8.84%
buffers/buffer-iterate.js n=1000 method='iterator' type='fast' size=512                                                                                        -1.02 %       ±3.45%  ±4.59%  ±5.97%
buffers/buffer-normalize-encoding.js n=1000000 encoding='ascii'                                                                                                -1.12 %       ±1.17%  ±1.56%  ±2.03%
buffers/buffer-normalize-encoding.js n=1000000 encoding='base64'                                                                                               -0.72 %       ±3.25%  ±4.37%  ±5.76%
buffers/buffer-normalize-encoding.js n=1000000 encoding='BASE64'                                                                                                0.27 %       ±1.12%  ±1.50%  ±1.95%
buffers/buffer-normalize-encoding.js n=1000000 encoding='binary'                                                                                               -0.15 %       ±1.11%  ±1.47%  ±1.91%
buffers/buffer-normalize-encoding.js n=1000000 encoding='hex'                                                                                                   0.30 %       ±1.65%  ±2.20%  ±2.88%
buffers/buffer-normalize-encoding.js n=1000000 encoding='HEX'                                                                                                  -1.40 %       ±3.25%  ±4.36%  ±5.76%
buffers/buffer-normalize-encoding.js n=1000000 encoding='latin1'                                                                                                1.73 %       ±2.92%  ±3.92%  ±5.16%
buffers/buffer-normalize-encoding.js n=1000000 encoding='LATIN1'                                                                                               -2.22 %       ±3.45%  ±4.64%  ±6.14%
buffers/buffer-normalize-encoding.js n=1000000 encoding='UCS-2'                                                                                                -0.34 %       ±0.85%  ±1.13%  ±1.48%
buffers/buffer-normalize-encoding.js n=1000000 encoding='UCS2'                                                                                                 -3.25 %       ±4.30%  ±5.78%  ±7.65%
buffers/buffer-normalize-encoding.js n=1000000 encoding='utf-16le'                                                                                             -1.41 %       ±2.02%  ±2.70%  ±3.54%
buffers/buffer-normalize-encoding.js n=1000000 encoding='UTF-16LE'                                                                                              0.18 %       ±1.03%  ±1.37%  ±1.78%
buffers/buffer-normalize-encoding.js n=1000000 encoding='utf-8'                                                                                                -0.01 %       ±3.56%  ±4.76%  ±6.24%
buffers/buffer-normalize-encoding.js n=1000000 encoding='utf16le'                                                                                              -0.94 %       ±1.39%  ±1.85%  ±2.41%
buffers/buffer-normalize-encoding.js n=1000000 encoding='UTF16LE'                                                                                              -3.65 %       ±4.00%  ±5.37%  ±7.10%
buffers/buffer-normalize-encoding.js n=1000000 encoding='utf8'                                                                                                 -1.28 %       ±3.75%  ±5.01%  ±6.53%
buffers/buffer-normalize-encoding.js n=1000000 encoding='UTF8'                                                                                                 -2.56 %       ±2.97%  ±3.98%  ±5.23%
buffers/buffer-read-float.js n=1000000 value='big' endian='LE' type='Double'                                                                                    0.25 %       ±1.33%  ±1.77%  ±2.31%
buffers/buffer-read-float.js n=1000000 value='big' endian='LE' type='Float'                                                                                    -1.19 %       ±2.50%  ±3.34%  ±4.38%
buffers/buffer-read-float.js n=1000000 value='inf' endian='LE' type='Double'                                                                                   -1.05 %       ±3.70%  ±4.92%  ±6.41%
buffers/buffer-read-float.js n=1000000 value='inf' endian='LE' type='Float'                                                                                     0.02 %       ±0.74%  ±0.98%  ±1.28%
buffers/buffer-read-float.js n=1000000 value='nan' endian='LE' type='Double'                                                                                   -0.11 %       ±1.38%  ±1.83%  ±2.39%
buffers/buffer-read-float.js n=1000000 value='nan' endian='LE' type='Float'                                                                                     0.31 %       ±1.04%  ±1.39%  ±1.81%
buffers/buffer-read-float.js n=1000000 value='small' endian='LE' type='Double'                                                                                 -0.62 %       ±1.00%  ±1.33%  ±1.74%
buffers/buffer-read-float.js n=1000000 value='small' endian='LE' type='Float'                                                                                   1.10 %       ±2.44%  ±3.27%  ±4.31%
buffers/buffer-read-float.js n=1000000 value='zero' endian='LE' type='Double'                                                                                   1.66 %       ±2.60%  ±3.47%  ±4.56%
buffers/buffer-read-float.js n=1000000 value='zero' endian='LE' type='Float'                                                                                   -0.21 %       ±3.22%  ±4.29%  ±5.58%
buffers/buffer-read-with-byteLength.js byteLength=1 n=1000000 type='IntBE' buffer='fast'                                                               ***      4.08 %       ±0.66%  ±0.88%  ±1.15%
buffers/buffer-read-with-byteLength.js byteLength=1 n=1000000 type='IntLE' buffer='fast'                                                               ***      4.03 %       ±0.41%  ±0.54%  ±0.71%
buffers/buffer-read-with-byteLength.js byteLength=1 n=1000000 type='UIntBE' buffer='fast'                                                              ***      1.66 %       ±0.47%  ±0.63%  ±0.82%
buffers/buffer-read-with-byteLength.js byteLength=1 n=1000000 type='UIntLE' buffer='fast'                                                              ***      1.62 %       ±0.47%  ±0.63%  ±0.82%
buffers/buffer-read-with-byteLength.js byteLength=2 n=1000000 type='IntBE' buffer='fast'                                                                        0.11 %       ±2.52%  ±3.39%  ±4.49%
buffers/buffer-read-with-byteLength.js byteLength=2 n=1000000 type='IntLE' buffer='fast'                                                                       -1.53 %       ±3.45%  ±4.65%  ±6.18%
buffers/buffer-read-with-byteLength.js byteLength=2 n=1000000 type='UIntBE' buffer='fast'                                                                      -2.11 %       ±3.79%  ±5.11%  ±6.78%
buffers/buffer-read-with-byteLength.js byteLength=2 n=1000000 type='UIntLE' buffer='fast'                                                                       0.60 %       ±3.47%  ±4.62%  ±6.01%
buffers/buffer-read-with-byteLength.js byteLength=3 n=1000000 type='IntBE' buffer='fast'                                                               ***     -2.82 %       ±0.84%  ±1.12%  ±1.46%
buffers/buffer-read-with-byteLength.js byteLength=3 n=1000000 type='IntLE' buffer='fast'                                                               ***     -4.13 %       ±2.31%  ±3.10%  ±4.08%
buffers/buffer-read-with-byteLength.js byteLength=3 n=1000000 type='UIntBE' buffer='fast'                                                              ***     -2.78 %       ±0.78%  ±1.04%  ±1.36%
buffers/buffer-read-with-byteLength.js byteLength=3 n=1000000 type='UIntLE' buffer='fast'                                                              ***     -2.47 %       ±0.85%  ±1.13%  ±1.48%
buffers/buffer-read-with-byteLength.js byteLength=4 n=1000000 type='IntBE' buffer='fast'                                                                       -1.53 %       ±3.13%  ±4.21%  ±5.58%
buffers/buffer-read-with-byteLength.js byteLength=4 n=1000000 type='IntLE' buffer='fast'                                                                 *     -2.92 %       ±2.89%  ±3.89%  ±5.16%
buffers/buffer-read-with-byteLength.js byteLength=4 n=1000000 type='UIntBE' buffer='fast'                                                                      -1.96 %       ±3.80%  ±5.06%  ±6.59%
buffers/buffer-read-with-byteLength.js byteLength=4 n=1000000 type='UIntLE' buffer='fast'                                                                      -1.99 %       ±2.42%  ±3.26%  ±4.31%
buffers/buffer-read-with-byteLength.js byteLength=5 n=1000000 type='IntBE' buffer='fast'                                                               ***     -4.13 %       ±0.72%  ±0.96%  ±1.24%
buffers/buffer-read-with-byteLength.js byteLength=5 n=1000000 type='IntLE' buffer='fast'                                                               ***     -4.31 %       ±1.24%  ±1.66%  ±2.18%
buffers/buffer-read-with-byteLength.js byteLength=5 n=1000000 type='UIntBE' buffer='fast'                                                              ***     -4.70 %       ±1.13%  ±1.51%  ±1.99%
buffers/buffer-read-with-byteLength.js byteLength=5 n=1000000 type='UIntLE' buffer='fast'                                                                *     -2.75 %       ±2.25%  ±3.01%  ±3.95%
buffers/buffer-read-with-byteLength.js byteLength=6 n=1000000 type='IntBE' buffer='fast'                                                               ***     -8.47 %       ±2.58%  ±3.47%  ±4.60%
buffers/buffer-read-with-byteLength.js byteLength=6 n=1000000 type='IntLE' buffer='fast'                                                               ***     -7.86 %       ±2.25%  ±3.02%  ±3.99%
buffers/buffer-read-with-byteLength.js byteLength=6 n=1000000 type='UIntBE' buffer='fast'                                                              ***     -7.07 %       ±3.48%  ±4.63%  ±6.02%
buffers/buffer-read-with-byteLength.js byteLength=6 n=1000000 type='UIntLE' buffer='fast'                                                              ***     -8.28 %       ±2.50%  ±3.34%  ±4.40%
buffers/buffer-read.js n=1000000 type='BigInt64BE' buffer='fast'                                                                                                0.45 %       ±1.25%  ±1.66%  ±2.16%
buffers/buffer-read.js n=1000000 type='BigInt64LE' buffer='fast'                                                                                               -0.09 %       ±1.25%  ±1.66%  ±2.17%
buffers/buffer-read.js n=1000000 type='BigUInt64BE' buffer='fast'                                                                                               1.28 %       ±2.10%  ±2.81%  ±3.70%
buffers/buffer-read.js n=1000000 type='BigUInt64LE' buffer='fast'                                                                                              -0.28 %       ±0.95%  ±1.27%  ±1.65%
buffers/buffer-read.js n=1000000 type='Int16BE' buffer='fast'                                                                                                   0.26 %       ±1.06%  ±1.42%  ±1.85%
buffers/buffer-read.js n=1000000 type='Int16LE' buffer='fast'                                                                                                  -0.48 %       ±2.71%  ±3.65%  ±4.83%
buffers/buffer-read.js n=1000000 type='Int32BE' buffer='fast'                                                                                                  -1.76 %       ±2.36%  ±3.17%  ±4.18%
buffers/buffer-read.js n=1000000 type='Int32LE' buffer='fast'                                                                                                  -0.49 %       ±2.35%  ±3.15%  ±4.17%
buffers/buffer-read.js n=1000000 type='Int8' buffer='fast'                                                                                                     -0.10 %       ±1.13%  ±1.50%  ±1.96%
buffers/buffer-read.js n=1000000 type='UInt16BE' buffer='fast'                                                                                                 -0.45 %       ±2.76%  ±3.70%  ±4.90%
buffers/buffer-read.js n=1000000 type='UInt16LE' buffer='fast'                                                                                                  0.54 %       ±1.28%  ±1.71%  ±2.22%
buffers/buffer-read.js n=1000000 type='UInt32BE' buffer='fast'                                                                                                 -2.15 %       ±2.58%  ±3.46%  ±4.56%
buffers/buffer-read.js n=1000000 type='UInt32LE' buffer='fast'                                                                                                 -0.34 %       ±0.94%  ±1.25%  ±1.63%
buffers/buffer-read.js n=1000000 type='UInt8' buffer='fast'                                                                                                     1.84 %       ±1.89%  ±2.54%  ±3.34%
buffers/buffer-slice.js n=1000000 type='fast'                                                                                                                  -1.79 %       ±8.14% ±10.84% ±14.11%
buffers/buffer-slice.js n=1000000 type='slow'                                                                                                                   4.10 %       ±8.54% ±11.37% ±14.80%
buffers/buffer-slice.js n=1000000 type='subarray'                                                                                                              -4.59 %       ±9.20% ±12.25% ±15.96%
buffers/buffer-swap.js n=1000000 len=1024 method='swap16' aligned='false'                                                                                      -0.88 %       ±2.00%  ±2.67%  ±3.51%
buffers/buffer-swap.js n=1000000 len=1024 method='swap16' aligned='true'                                                                                       -1.07 %       ±2.69%  ±3.59%  ±4.70%
buffers/buffer-swap.js n=1000000 len=1024 method='swap32' aligned='false'                                                                                      -0.09 %       ±0.23%  ±0.31%  ±0.40%
buffers/buffer-swap.js n=1000000 len=1024 method='swap32' aligned='true'                                                                                        0.10 %       ±0.19%  ±0.25%  ±0.33%
buffers/buffer-swap.js n=1000000 len=1024 method='swap64' aligned='false'                                                                                      -0.55 %       ±0.96%  ±1.29%  ±1.70%
buffers/buffer-swap.js n=1000000 len=1024 method='swap64' aligned='true'                                                                                       -0.45 %       ±1.03%  ±1.38%  ±1.81%
buffers/buffer-swap.js n=1000000 len=2056 method='swap16' aligned='false'                                                                                      -0.70 %       ±0.87%  ±1.17%  ±1.55%
buffers/buffer-swap.js n=1000000 len=2056 method='swap16' aligned='true'                                                                                       -0.06 %       ±0.34%  ±0.45%  ±0.59%
buffers/buffer-swap.js n=1000000 len=2056 method='swap32' aligned='false'                                                                                      -0.08 %       ±0.15%  ±0.19%  ±0.25%
buffers/buffer-swap.js n=1000000 len=2056 method='swap32' aligned='true'                                                                                        0.03 %       ±0.19%  ±0.25%  ±0.33%
buffers/buffer-swap.js n=1000000 len=2056 method='swap64' aligned='false'                                                                                       0.06 %       ±0.59%  ±0.79%  ±1.03%
buffers/buffer-swap.js n=1000000 len=2056 method='swap64' aligned='true'                                                                                 *      0.26 %       ±0.24%  ±0.32%  ±0.41%
buffers/buffer-swap.js n=1000000 len=256 method='swap16' aligned='false'                                                                                        0.91 %       ±7.08%  ±9.42% ±12.26%
buffers/buffer-swap.js n=1000000 len=256 method='swap16' aligned='true'                                                                                         4.24 %       ±9.79% ±13.03% ±16.96%
buffers/buffer-swap.js n=1000000 len=256 method='swap32' aligned='false'                                                                                        1.05 %       ±4.69%  ±6.24%  ±8.12%
buffers/buffer-swap.js n=1000000 len=256 method='swap32' aligned='true'                                                                                         0.54 %       ±2.67%  ±3.56%  ±4.63%
buffers/buffer-swap.js n=1000000 len=256 method='swap64' aligned='false'                                                                                       -4.36 %       ±5.31%  ±7.07%  ±9.22%
buffers/buffer-swap.js n=1000000 len=256 method='swap64' aligned='true'                                                                                        -1.35 %       ±3.73%  ±4.97%  ±6.46%
buffers/buffer-swap.js n=1000000 len=64 method='swap16' aligned='false'                                                                                         1.29 %       ±2.98%  ±3.97%  ±5.16%
buffers/buffer-swap.js n=1000000 len=64 method='swap16' aligned='true'                                                                                         -4.02 %       ±6.81%  ±9.07% ±11.80%
buffers/buffer-swap.js n=1000000 len=64 method='swap32' aligned='false'                                                                                         2.59 %       ±5.99%  ±7.97% ±10.38%
buffers/buffer-swap.js n=1000000 len=64 method='swap32' aligned='true'                                                                                         -2.40 %       ±4.37%  ±5.83%  ±7.59%
buffers/buffer-swap.js n=1000000 len=64 method='swap64' aligned='false'                                                                                        -4.41 %       ±6.45%  ±8.58% ±11.17%
buffers/buffer-swap.js n=1000000 len=64 method='swap64' aligned='true'                                                                                          0.42 %       ±6.33%  ±8.42% ±10.97%
buffers/buffer-swap.js n=1000000 len=768 method='swap16' aligned='false'                                                                                       -1.42 %       ±2.49%  ±3.34%  ±4.38%
buffers/buffer-swap.js n=1000000 len=768 method='swap16' aligned='true'                                                                                         3.63 %       ±3.97%  ±5.31%  ±6.96%
buffers/buffer-swap.js n=1000000 len=768 method='swap32' aligned='false'                                                                                       -0.29 %       ±0.31%  ±0.42%  ±0.54%
buffers/buffer-swap.js n=1000000 len=768 method='swap32' aligned='true'                                                                                        -0.18 %       ±0.32%  ±0.43%  ±0.56%
buffers/buffer-swap.js n=1000000 len=768 method='swap64' aligned='false'                                                                                       -0.65 %       ±2.10%  ±2.79%  ±3.64%
buffers/buffer-swap.js n=1000000 len=768 method='swap64' aligned='true'                                                                                        -0.13 %       ±1.18%  ±1.57%  ±2.04%
buffers/buffer-swap.js n=1000000 len=8192 method='swap16' aligned='false'                                                                                       0.01 %       ±0.17%  ±0.22%  ±0.29%
buffers/buffer-swap.js n=1000000 len=8192 method='swap16' aligned='true'                                                                                       -0.04 %       ±0.17%  ±0.22%  ±0.29%
buffers/buffer-swap.js n=1000000 len=8192 method='swap32' aligned='false'                                                                                      -0.06 %       ±0.10%  ±0.13%  ±0.17%
buffers/buffer-swap.js n=1000000 len=8192 method='swap32' aligned='true'                                                                                 *     -0.10 %       ±0.09%  ±0.12%  ±0.15%
buffers/buffer-swap.js n=1000000 len=8192 method='swap64' aligned='false'                                                                                      -0.12 %       ±0.16%  ±0.22%  ±0.28%
buffers/buffer-swap.js n=1000000 len=8192 method='swap64' aligned='true'                                                                                       -0.08 %       ±0.14%  ±0.18%  ±0.24%
buffers/buffer-tojson.js len=0 n=10000                                                                                                                  **     -4.33 %       ±3.19%  ±4.25%  ±5.55%
buffers/buffer-tojson.js len=256 n=10000                                                                                                                        0.81 %       ±2.24%  ±2.99%  ±3.90%
buffers/buffer-tojson.js len=4096 n=10000                                                                                                                      -2.52 %       ±6.20%  ±8.26% ±10.79%
buffers/buffer-tostring.js n=1000000 len=1 args=0 encoding=''                                                                                                   2.90 %       ±8.32% ±11.08% ±14.45%
buffers/buffer-tostring.js n=1000000 len=1 args=1 encoding='ascii'                                                                                             -3.01 %       ±6.09%  ±8.11% ±10.56%
buffers/buffer-tostring.js n=1000000 len=1 args=1 encoding='hex'                                                                                                1.34 %       ±4.65%  ±6.19%  ±8.06%
buffers/buffer-tostring.js n=1000000 len=1 args=1 encoding='latin1'                                                                                            -1.28 %       ±6.39%  ±8.50% ±11.06%
buffers/buffer-tostring.js n=1000000 len=1 args=1 encoding='UCS-2'                                                                                              1.58 %       ±7.26%  ±9.66% ±12.58%
buffers/buffer-tostring.js n=1000000 len=1 args=1 encoding='utf8'                                                                                              -2.41 %       ±8.90% ±11.85% ±15.42%
buffers/buffer-tostring.js n=1000000 len=1 args=3 encoding='ascii'                                                                                             -1.13 %       ±5.60%  ±7.45%  ±9.70%
buffers/buffer-tostring.js n=1000000 len=1 args=3 encoding='hex'                                                                                                4.01 %       ±7.44%  ±9.90% ±12.89%
buffers/buffer-tostring.js n=1000000 len=1 args=3 encoding='latin1'                                                                                             1.48 %       ±7.39%  ±9.83% ±12.79%
buffers/buffer-tostring.js n=1000000 len=1 args=3 encoding='UCS-2'                                                                                             -1.24 %       ±5.60%  ±7.45%  ±9.70%
buffers/buffer-tostring.js n=1000000 len=1 args=3 encoding='utf8'                                                                                               6.12 %       ±7.08%  ±9.43% ±12.29%
buffers/buffer-tostring.js n=1000000 len=1024 args=0 encoding=''                                                                                               -2.05 %       ±4.53%  ±6.03%  ±7.86%
buffers/buffer-tostring.js n=1000000 len=1024 args=1 encoding='ascii'                                                                                   **     -5.73 %       ±3.70%  ±4.92%  ±6.40%
buffers/buffer-tostring.js n=1000000 len=1024 args=1 encoding='hex'                                                                                             0.22 %       ±0.72%  ±0.96%  ±1.25%
buffers/buffer-tostring.js n=1000000 len=1024 args=1 encoding='latin1'                                                                                   *     -4.22 %       ±4.18%  ±5.56%  ±7.24%
buffers/buffer-tostring.js n=1000000 len=1024 args=1 encoding='UCS-2'                                                                                    *     -3.98 %       ±3.63%  ±4.84%  ±6.29%
buffers/buffer-tostring.js n=1000000 len=1024 args=1 encoding='utf8'                                                                                     *     -4.06 %       ±3.40%  ±4.53%  ±5.89%
buffers/buffer-tostring.js n=1000000 len=1024 args=3 encoding='ascii'                                                                                          -3.09 %       ±4.23%  ±5.63%  ±7.33%
buffers/buffer-tostring.js n=1000000 len=1024 args=3 encoding='hex'                                                                                            -0.10 %       ±0.68%  ±0.91%  ±1.19%
buffers/buffer-tostring.js n=1000000 len=1024 args=3 encoding='latin1'                                                                                         -2.69 %       ±3.47%  ±4.62%  ±6.02%
buffers/buffer-tostring.js n=1000000 len=1024 args=3 encoding='UCS-2'                                                                                          -1.71 %       ±3.39%  ±4.51%  ±5.88%
buffers/buffer-tostring.js n=1000000 len=1024 args=3 encoding='utf8'                                                                                    **     -5.16 %       ±3.36%  ±4.47%  ±5.82%
buffers/buffer-tostring.js n=1000000 len=64 args=0 encoding=''                                                                                                  4.42 %       ±9.53% ±12.68% ±16.50%
buffers/buffer-tostring.js n=1000000 len=64 args=1 encoding='ascii'                                                                                             1.41 %       ±7.57% ±10.08% ±13.11%
buffers/buffer-tostring.js n=1000000 len=64 args=1 encoding='hex'                                                                                              -1.78 %       ±4.09%  ±5.44%  ±7.09%
buffers/buffer-tostring.js n=1000000 len=64 args=1 encoding='latin1'                                                                                            1.20 %       ±6.19%  ±8.23% ±10.72%
buffers/buffer-tostring.js n=1000000 len=64 args=1 encoding='UCS-2'                                                                                             4.76 %       ±5.92%  ±7.88% ±10.26%
buffers/buffer-tostring.js n=1000000 len=64 args=1 encoding='utf8'                                                                                              4.11 %       ±6.99%  ±9.31% ±12.12%
buffers/buffer-tostring.js n=1000000 len=64 args=3 encoding='ascii'                                                                                            -3.07 %       ±5.08%  ±6.76%  ±8.80%
buffers/buffer-tostring.js n=1000000 len=64 args=3 encoding='hex'                                                                                              -0.64 %       ±4.75%  ±6.32%  ±8.23%
buffers/buffer-tostring.js n=1000000 len=64 args=3 encoding='latin1'                                                                                            1.63 %       ±7.59% ±10.10% ±13.14%
buffers/buffer-tostring.js n=1000000 len=64 args=3 encoding='UCS-2'                                                                                            -3.09 %       ±5.01%  ±6.67%  ±8.70%
buffers/buffer-tostring.js n=1000000 len=64 args=3 encoding='utf8'                                                                                             -2.48 %       ±6.42%  ±8.55% ±11.13%
buffers/buffer-write-string.js n=1000000 len=2048 args='' encoding=''                                                                                          -3.17 %       ±4.41%  ±5.87%  ±7.64%
buffers/buffer-write-string.js n=1000000 len=2048 args='' encoding='ascii'                                                                                     -2.56 %       ±4.26%  ±5.68%  ±7.42%
buffers/buffer-write-string.js n=1000000 len=2048 args='' encoding='hex'                                                                                 *      1.21 %       ±0.99%  ±1.32%  ±1.73%
buffers/buffer-write-string.js n=1000000 len=2048 args='' encoding='latin1'                                                                                    -0.74 %       ±5.95%  ±7.91% ±10.30%
buffers/buffer-write-string.js n=1000000 len=2048 args='' encoding='utf16le'                                                                                   -2.62 %       ±4.94%  ±6.57%  ±8.56%
buffers/buffer-write-string.js n=1000000 len=2048 args='' encoding='utf8'                                                                                      -1.88 %       ±3.76%  ±5.01%  ±6.54%
buffers/buffer-write-string.js n=1000000 len=2048 args='offset' encoding=''                                                                                    -0.15 %       ±5.12%  ±6.81%  ±8.87%
buffers/buffer-write-string.js n=1000000 len=2048 args='offset' encoding='ascii'                                                                                4.01 %       ±6.54%  ±8.71% ±11.34%
buffers/buffer-write-string.js n=1000000 len=2048 args='offset' encoding='hex'                                                                                  0.01 %       ±1.69%  ±2.25%  ±2.93%
buffers/buffer-write-string.js n=1000000 len=2048 args='offset' encoding='latin1'                                                                               3.08 %       ±6.20%  ±8.26% ±10.76%
buffers/buffer-write-string.js n=1000000 len=2048 args='offset' encoding='utf16le'                                                                             -2.66 %       ±6.10%  ±8.12% ±10.57%
buffers/buffer-write-string.js n=1000000 len=2048 args='offset' encoding='utf8'                                                                                -0.25 %       ±3.32%  ±4.42%  ±5.75%
buffers/buffer-write-string.js n=1000000 len=2048 args='offset+length' encoding=''                                                                             -1.82 %       ±3.70%  ±4.92%  ±6.40%
buffers/buffer-write-string.js n=1000000 len=2048 args='offset+length' encoding='ascii'                                                                  *      5.88 %       ±4.79%  ±6.39%  ±8.36%
buffers/buffer-write-string.js n=1000000 len=2048 args='offset+length' encoding='hex'                                                                           0.19 %       ±0.67%  ±0.89%  ±1.16%
buffers/buffer-write-string.js n=1000000 len=2048 args='offset+length' encoding='latin1'                                                                       -1.86 %       ±4.64%  ±6.18%  ±8.04%
buffers/buffer-write-string.js n=1000000 len=2048 args='offset+length' encoding='utf16le'                                                                       2.73 %       ±5.24%  ±6.97%  ±9.07%
buffers/buffer-write-string.js n=1000000 len=2048 args='offset+length' encoding='utf8'                                                                         -2.18 %       ±2.37%  ±3.16%  ±4.11%
buffers/buffer-write.js n=1000000 type='BigInt64BE' buffer='fast'                                                                                              -2.24 %       ±7.19%  ±9.56% ±12.45%
buffers/buffer-write.js n=1000000 type='BigInt64LE' buffer='fast'                                                                                              -5.49 %       ±6.98%  ±9.31% ±12.16%
buffers/buffer-write.js n=1000000 type='BigUInt64BE' buffer='fast'                                                                                             -0.00 %       ±5.41%  ±7.20%  ±9.38%
buffers/buffer-write.js n=1000000 type='BigUInt64LE' buffer='fast'                                                                                              1.76 %       ±6.01%  ±8.00% ±10.42%
buffers/buffer-write.js n=1000000 type='DoubleBE' buffer='fast'                                                                                                 3.19 %       ±7.00%  ±9.31% ±12.12%
buffers/buffer-write.js n=1000000 type='DoubleLE' buffer='fast'                                                                                                -2.27 %       ±7.17%  ±9.54% ±12.41%
buffers/buffer-write.js n=1000000 type='FloatBE' buffer='fast'                                                                                           *      7.48 %       ±6.76%  ±9.02% ±11.80%
buffers/buffer-write.js n=1000000 type='FloatLE' buffer='fast'                                                                                                 -1.15 %       ±7.02%  ±9.34% ±12.15%
buffers/buffer-write.js n=1000000 type='Int16BE' buffer='fast'                                                                                                  3.67 %       ±7.06%  ±9.40% ±12.23%
buffers/buffer-write.js n=1000000 type='Int16LE' buffer='fast'                                                                                                  0.54 %       ±7.74% ±10.30% ±13.41%
buffers/buffer-write.js n=1000000 type='Int32BE' buffer='fast'                                                                                                  1.50 %       ±6.75%  ±8.99% ±11.70%
buffers/buffer-write.js n=1000000 type='Int32LE' buffer='fast'                                                                                                  0.40 %       ±6.36%  ±8.47% ±11.02%
buffers/buffer-write.js n=1000000 type='Int8' buffer='fast'                                                                                                    -2.51 %       ±7.75% ±10.31% ±13.41%
buffers/buffer-write.js n=1000000 type='IntBE' buffer='fast'                                                                                                   -4.69 %       ±9.58% ±12.74% ±16.59%
buffers/buffer-write.js n=1000000 type='IntLE' buffer='fast'                                                                                                   -4.75 %       ±8.54% ±11.36% ±14.79%
buffers/buffer-write.js n=1000000 type='UInt16BE' buffer='fast'                                                                                                -1.77 %       ±7.74% ±10.29% ±13.40%
buffers/buffer-write.js n=1000000 type='UInt16LE' buffer='fast'                                                                                                -5.25 %       ±8.15% ±10.84% ±14.12%
buffers/buffer-write.js n=1000000 type='UInt32BE' buffer='fast'                                                                                          *     -8.34 %       ±7.42%  ±9.87% ±12.85%
buffers/buffer-write.js n=1000000 type='UInt32LE' buffer='fast'                                                                                                 2.62 %       ±7.77% ±10.34% ±13.46%
buffers/buffer-write.js n=1000000 type='UInt8' buffer='fast'                                                                                                   -3.80 %       ±7.78% ±10.35% ±13.48%
buffers/buffer-write.js n=1000000 type='UIntBE' buffer='fast'                                                                                                  -3.85 %       ±8.23% ±10.96% ±14.26%
buffers/buffer-write.js n=1000000 type='UIntLE' buffer='fast'                                                                                                   2.47 %       ±8.14% ±10.83% ±14.10%
buffers/buffer-zero.js type='buffer' n=1000000                                                                                                                  1.42 %       ±3.48%  ±4.67%  ±6.16%
buffers/buffer-zero.js type='string' n=1000000                                                                                                                 -4.62 %       ±6.30%  ±8.41% ±11.00%
buffers/dataview-set.js n=1000000 type='Float32BE'                                                                                                             -0.14 %       ±0.73%  ±0.97%  ±1.26%
buffers/dataview-set.js n=1000000 type='Float32LE'                                                                                                       *     -0.86 %       ±0.80%  ±1.06%  ±1.38%
buffers/dataview-set.js n=1000000 type='Float64BE'                                                                                                             -0.04 %       ±1.12%  ±1.50%  ±1.95%
buffers/dataview-set.js n=1000000 type='Float64LE'                                                                                                             -0.02 %       ±0.57%  ±0.76%  ±0.99%
buffers/dataview-set.js n=1000000 type='Int16BE'                                                                                                                0.53 %       ±1.42%  ±1.88%  ±2.45%
buffers/dataview-set.js n=1000000 type='Int16LE'                                                                                                                0.32 %       ±1.48%  ±1.97%  ±2.56%
buffers/dataview-set.js n=1000000 type='Int32BE'                                                                                                               -0.54 %       ±1.21%  ±1.61%  ±2.09%
buffers/dataview-set.js n=1000000 type='Int32LE'                                                                                                               -0.30 %       ±1.34%  ±1.78%  ±2.31%
buffers/dataview-set.js n=1000000 type='Int8'                                                                                                                  -1.10 %       ±1.24%  ±1.65%  ±2.14%
buffers/dataview-set.js n=1000000 type='Uint16BE'                                                                                                               0.37 %       ±1.34%  ±1.79%  ±2.33%
buffers/dataview-set.js n=1000000 type='Uint16LE'                                                                                                              -0.15 %       ±1.42%  ±1.89%  ±2.47%
buffers/dataview-set.js n=1000000 type='Uint32BE'                                                                                                               0.96 %       ±1.38%  ±1.86%  ±2.45%
buffers/dataview-set.js n=1000000 type='Uint32LE'                                                                                                              -0.11 %       ±0.91%  ±1.22%  ±1.61%
buffers/dataview-set.js n=1000000 type='Uint8'                                                                                                                 -0.64 %       ±1.26%  ±1.68%  ±2.19%

Be aware that when doing many comparisons the risk of a false-positive
result increases. In this case, there are 396 comparisons, you can thus
expect the following amount of false-positive results:
  19.80 false positives, when considering a   5% risk acceptance (*, **, ***),
  3.96 false positives, when considering a   1% risk acceptance (**, ***),
  0.40 false positives, when considering a 0.1% risk acceptance (***)
@Uzlopak
Copy link
Contributor

Uzlopak commented Dec 29, 2023

Looks more like an overall loss.

@H4ad
Copy link
Member

H4ad commented Dec 29, 2023

Even if the results are not positive, at least they are interesting, there is something on v8 that is making if statements faster than switch statements? If this is right, maybe we should take a look at another place where we use switch and run the benchmarks using if statements.


@mcollina @RafaelGSS do you guys have any take on these results? Otherwise, I think we should close this one.


@sanjaiyan-dev Do the benchmarks make sense to you? In case you want to run those benchmarks locally to try understand why it was slower, you can follow the guide of benchmarks and then run buffer-read-with-byteLength.js, which is the benchmark that is more impacted by your change.

@tniessen
Copy link
Member

Even if the results are not positive, at least they are interesting, there is something on v8 that is making if statements faster than switch statements? If this is right, maybe we should take a look at another place where we use switch and run the benchmarks using if statements.

FWIW, such micro-optimizations are things that we'd have to benchmark after every V8 update, possibly even on every supported architecture.

@Uzlopak
Copy link
Contributor

Uzlopak commented Dec 29, 2023

I actually dont understand why switch cases where we check for integers are not put in an array.

@sanjaiyan-dev
Copy link
Contributor Author

@sanjaiyan-dev Do the benchmarks make sense to you? In case you want to run those benchmarks locally to try understand why it was slower, you can follow the guide of benchmarks and then run buffer-read-with-byteLength.js, which is the benchmark that is more impacted by your change.

Hello, certainly, I will attempt to run the benchmarks on my local machine. I apologize for any inconvenience caused.

@sanjaiyan-dev
Copy link
Contributor Author

I actually dont understand why switch cases where we check for integers are not put in an array.

I sincerely apologize; I couldn't understand you.

@benjamingr
Copy link
Member

@H4ad hint - run the code through systems analyzer and see the IR difference: https://v8.github.io/tools/head/system-analyzer/index.html

I don't find this version more readable and as it is also measurably slower I don't think we should merge this.

Thanks for the PR though <3

@peterver
Copy link

peterver commented Mar 2, 2024

I am confused. I would expect that putting some stuff in an array is faster.

I would definitely look at benchmarking the array index lookup (which might not work for certain functions but I feel could increase the speed for functions where possible). Here's an example test (I know not necessarily real-world but the results were interesting).

Output was the following on local hardware:

Using Array                                                 | 827155207           
Using If                                                    | 241405135           
Using Map                                                   | 167265356           
Using Switch                                                | 289138808

(ps: I took out Fastbuffer locally as I didn't have it, this was really just a raw test because I was curious).

Hope it helps :)!

script:

const idxmap = new Map([
    [0, Int8Array],
    [1, Uint8Array],
    [2, Uint8ClampedArray],
    [3, Int16Array],
    [4, Uint16Array],
    [5, Int32Array],
    [6, Uint32Array],
    [7, Float32Array],
    [8, Float64Array],
    [9, DataView],
    [11, BigInt64Array],
    [12, BigUint64Array],
]);

const idxarr = [
    Int8Array,
    Uint8Array,
    Uint8ClampedArray,
    Int16Array,
    Uint16Array,
    Int32Array,
    Uint32Array,
    Float32Array,
    Float64Array,
    DataView,
    BigInt64Array,
    BigUint64Array,
];

function usingIf (idx) {
  if (idx === 0) return Int8Array;
  if (idx === 1) return Uint8Array;
  if (idx === 2) return Uint8ClampedArray;
  if (idx === 3) return Int16Array;
  if (idx === 4) return Uint16Array;
  if (idx === 5) return Int32Array;
  if (idx === 6) return Uint32Array;
  if (idx === 7) return Float32Array;
  if (idx === 8) return Float64Array;
  if (idx === 9) return DataView;
  if (idx === 11) return BigInt64Array;
  if (idx === 12) return BigUint64Array;
  return undefined;
}

function usingSwitch (idx) {
  switch (idx) {
    case 0: return Int8Array;
    case 1: return Uint8Array;
    case 2: return Uint8ClampedArray;
    case 3: return Int16Array;
    case 4: return Uint16Array;
    case 5: return Int32Array;
    case 6: return Uint32Array;
    case 7: return Float32Array;
    case 8: return Float64Array;
    case 9: return DataView;
    case 11: return BigInt64Array;
    case 12: return BigUint64Array;
    default: return undefined;
  }
}

function usingMap (idx) {
    return idxmap.get(idx) || undefined;
}

function usingArray (idx) {
    return idxarr[idx] || undefined;
}

//  Bench util

const ROW_TEST_WIDTH    = 60;
const ROW_OPS_WIDTH     = 20;
const ITERATIONS        = 100000000;

function separator () {
    console.info(''.padEnd(ROW_TEST_WIDTH + ROW_OPS_WIDTH, '-'));
}

function bench (el) {
    let runtime = performance.now();
    for (let i = 0; i < ITERATIONS; i++) el.fn(9);
    runtime = performance.now() - runtime;
    const ops =  Math.floor(ITERATIONS * (1000/runtime));
    console.info([el.lbl.padEnd(ROW_TEST_WIDTH, ' '), `${ops}`.padEnd(ROW_OPS_WIDTH, ' ')].join('| '));
}

bench({fn: usingArray, lbl: 'Using Array'});
bench({fn: usingIf, lbl: 'Using If'});
bench({fn: usingMap, lbl: 'Using Map'});
bench({fn: usingSwitch, lbl: 'Using Switch'});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
buffer Issues and PRs related to the buffer subsystem. needs-ci PRs that need a full CI run. performance Issues and PRs related to the performance of Node.js.