---
title: "Comment by Agnius Vasiliauskas on \"Top 10 JavaScript Hack for Optimized Performance\" | Hashnode"
description: "Nice article, I especially liked part about HTTP/2 multiplexing, indeed - every web server should make this requirement a MUST HAVE . However I can&#39;t agree"
url: "https://hashnode.com/posts/top-10-javascript-hack-for-optimized-performance/5d02400736a0034c13ed018c/comment/5d03909bbf4e2c1e5aeba286"
---

[Discussion](https://hashnode.com/posts/top-10-javascript-hack-for-optimized-performance/5d02400736a0034c13ed018c)

Comment [Top 10 JavaScript Hack for Optimized Performance](https://hashnode.com/posts/top-10-javascript-hack-for-optimized-performance/5d02400736a0034c13ed018c)

[Agnius Vasiliauskas](https://hashnode.com/@AgniusVasiliauskas)

[Jun 14, 2019](https://hashnode.com/posts/top-10-javascript-hack-for-optimized-performance/5d02400736a0034c13ed018c/comment/5d03909bbf4e2c1e5aeba286)

Nice article, I especially liked part about HTTP/2 multiplexing, indeed - every web server should make this requirement a **MUST HAVE**. However I can't agree on your note that :

> Using the Switch case over if/else enables developers to shorten execution time

I can't believe in this - at a lower level **both** code structures should be compiled into some sort of _goto_ conditional jumps. Let's check. I've made a JS benchmark. This is switch block:

```
var rnd = Math.floor(Math.random() * 5);
switch(rnd) {
  case 1:
    rnd += 1;
    break;
  case 2:
    rnd += 2;
    break;
  default:
    rnd += -1;
}
```

and this is if/else block :

```
var rnd = Math.floor(Math.random() * 5);
if (rnd == 1) {
    rnd += 1;
}
else if (rnd == 2) {
    rnd += 2;
}
else {
    rnd += -1;
}
```

After pasting these blocks into [jsbench.me](https://jsbench.me/) performance comparison suite,- I've got results that **switch** block is SLOWER by _\[0% - 2%\]_ on average. Given many unknown factors - how these tests are executed, JS implementation differences between browsers, execution speed measurement errors, biased outcome (maybe after 1000 or more runs performance difference would be 0%) and etc. - it would be rational to neglect these small execution time differences and for practical purposes keep that both should run at the same rate.
