Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Switch vs Prepared Object Literal vs Prepared Array vs Prepared Map
(version: 0)
Comparing performance of:
Switch vs Object Literal vs Array Literal vs Map Literal
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var arrayLiteral = [ function(){return 'a' + '0' + Math.random(); } ,function(){return 'b' + '1' + Math.random(); } ,function(){return 'c' + '2' + Math.random(); } ,function(){return 'd' + '3' + Math.random(); } ,function(){return 'e' + '4' + Math.random(); } ,function(){return 'f' + '5' + Math.random(); } ,function(){return 'g' + '6' + Math.random(); } ,function(){return 'h' + '7' + Math.random(); } ,function(){return 'i' + '8' + Math.random(); } ,function(){return 'j' + '9' + Math.random(); } ,function(){return 'k' + '10' + Math.random(); } ,function(){return 'l' + '11' + Math.random(); } ,function(){return 'm' + '12' + Math.random(); } ,function(){return 'n' + '13' + Math.random(); } ,function(){return 'o' + '14' + Math.random(); } ,function(){return 'p' + '15' + Math.random(); } ,function(){return 'q' + '16' + Math.random(); } ,function(){return 'r' + '17' + Math.random(); } ,function(){return 's' + '18' + Math.random(); } ,function(){return 't' + '19' + Math.random(); } ,function(){return 'u' + '20' + Math.random(); } ,function(){return 'v' + '21' + Math.random(); } ,function(){return 'w' + '22' + Math.random(); } ,function(){return 'x' + '23' + Math.random(); } ,function(){return 'y' + '24' + Math.random(); } ,function(){return 'z' + '25' + Math.random(); } ,function(){return 'A' + '26' + Math.random(); } ,function(){return 'B' + '27' + Math.random(); } ,function(){return 'C' + '28' + Math.random(); } ,function(){return 'D' + '29' + Math.random(); } ,function(){return 'E' + '30' + Math.random(); } ,function(){return 'F' + '31' + Math.random(); } ,function(){return 'G' + '32' + Math.random(); } ,function(){return 'H' + '33' + Math.random(); } ,function(){return 'I' + '34' + Math.random(); } ,function(){return 'J' + '35' + Math.random(); } ,function(){return 'K' + '36' + Math.random(); } ,function(){return 'L' + '37' + Math.random(); } ,function(){return 'M' + '38' + Math.random(); } ,function(){return 'N' + '39' + Math.random(); } ,function(){return 'O' + '40' + Math.random(); } ,function(){return 'P' + '41' + Math.random(); } ,function(){return 'Q' + '42' + Math.random(); } ,function(){return 'R' + '43' + Math.random(); } ,function(){return 'S' + '44' + Math.random(); } ,function(){return 'T' + '45' + Math.random(); } ,function(){return 'U' + '46' + Math.random(); } ,function(){return 'V' + '47' + Math.random(); } ,function(){return 'W' + '48' + Math.random(); } ,function(){return 'X' + '49' + Math.random(); } ,function(){return 'Y' + '50' + Math.random(); } ,function(){return 'Z' + '51' + Math.random(); } ,function(){return 'a' + '52' + Math.random(); } ,function(){return 'b' + '53' + Math.random(); } ,function(){return 'c' + '54' + Math.random(); } ,function(){return 'd' + '55' + Math.random(); } ,function(){return 'e' + '56' + Math.random(); } ,function(){return 'f' + '57' + Math.random(); } ,function(){return 'g' + '58' + Math.random(); } ,function(){return 'h' + '59' + Math.random(); } ,function(){return 'i' + '60' + Math.random(); } ,function(){return 'j' + '61' + Math.random(); } ,function(){return 'k' + '62' + Math.random(); } ,function(){return 'l' + '63' + Math.random(); } ]; var objLiteral = Object.fromEntries(arrayLiteral.entries()); var map = new Map(arrayLiteral.entries()); function usingSwitch(c) { switch (c) { case 0: 'a' + '0' + Math.random(); break; case 1: 'b' + '1' + Math.random(); break; case 2: 'c' + '2' + Math.random(); break; case 3: 'd' + '3' + Math.random(); break; case 4: 'e' + '4' + Math.random(); break; case 5: 'f' + '5' + Math.random(); break; case 6: 'g' + '6' + Math.random(); break; case 7: 'h' + '7' + Math.random(); break; case 8: 'i' + '8' + Math.random(); break; case 9: 'j' + '9' + Math.random(); break; case 10: 'k' + '10' + Math.random(); break; case 11: 'l' + '11' + Math.random(); break; case 12: 'm' + '12' + Math.random(); break; case 13: 'n' + '13' + Math.random(); break; case 14: 'o' + '14' + Math.random(); break; case 15: 'p' + '15' + Math.random(); break; case 16: 'q' + '16' + Math.random(); break; case 17: 'r' + '17' + Math.random(); break; case 18: 's' + '18' + Math.random(); break; case 19: 't' + '19' + Math.random(); break; case 20: 'u' + '20' + Math.random(); break; case 21: 'v' + '21' + Math.random(); break; case 22: 'w' + '22' + Math.random(); break; case 23: 'x' + '23' + Math.random(); break; case 24: 'y' + '24' + Math.random(); break; case 25: 'z' + '25' + Math.random(); break; case 26: 'A' + '26' + Math.random(); break; case 27: 'B' + '27' + Math.random(); break; case 28: 'C' + '28' + Math.random(); break; case 29: 'D' + '29' + Math.random(); break; case 30: 'E' + '30' + Math.random(); break; case 31: 'F' + '31' + Math.random(); break; case 32: 'G' + '32' + Math.random(); break; case 33: 'H' + '33' + Math.random(); break; case 34: 'I' + '34' + Math.random(); break; case 35: 'J' + '35' + Math.random(); break; case 36: 'K' + '36' + Math.random(); break; case 37: 'L' + '37' + Math.random(); break; case 38: 'M' + '38' + Math.random(); break; case 39: 'N' + '39' + Math.random(); break; case 40: 'O' + '40' + Math.random(); break; case 41: 'P' + '41' + Math.random(); break; case 42: 'Q' + '42' + Math.random(); break; case 43: 'R' + '43' + Math.random(); break; case 44: 'S' + '44' + Math.random(); break; case 45: 'T' + '45' + Math.random(); break; case 46: 'U' + '46' + Math.random(); break; case 47: 'V' + '47' + Math.random(); break; case 48: 'W' + '48' + Math.random(); break; case 49: 'X' + '49' + Math.random(); break; case 50: 'Y' + '50' + Math.random(); break; case 51: 'Z' + '51' + Math.random(); break; case 52: 'a' + '52' + Math.random(); break; case 53: 'b' + '53' + Math.random(); break; case 54: 'c' + '54' + Math.random(); break; case 55: 'd' + '55' + Math.random(); break; case 56: 'e' + '56' + Math.random(); break; case 57: 'f' + '57' + Math.random(); break; case 58: 'g' + '58' + Math.random(); break; case 59: 'h' + '59' + Math.random(); break; case 60: 'i' + '60' + Math.random(); break; case 61: 'j' + '61' + Math.random(); break; case 62: 'k' + '62' + Math.random(); break; case 63: 'l' + '63' + Math.random(); break; } }
Tests:
Switch
usingSwitch(~~(Math.random()*64))
Object Literal
objLiteral[~~(Math.random()*64)]();
Array Literal
arrayLiteral[~~(Math.random()*64)]();
Map Literal
map.get(~~(Math.random()*64))();
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Switch
Object Literal
Array Literal
Map Literal
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
The provided code seems to be generating random test cases for a JavaScript benchmarking script, likely using the `switch` statement and different data types (strings and numbers). To analyze this further, I'll break down the code into smaller parts: 1. **Test Cases Generation**: - The code generates 6 random test cases with unique names (`Switch`, `Object Literal`, `Array Literal`, etc.). Each test case has a corresponding benchmark definition. - The benchmark definitions are generated using the `switch` statement, which allows for varying execution patterns based on the randomly generated values. 2. **Code Snippet Analysis**: ```javascript case 1: 'S' + '44' + Math.random(); ``` This line generates a random string by concatenating `'S'`, `'44'`, and `Math.random()` (a pseudo-random number generator function in JavaScript). The result is then executed. 3. **Individual Test Cases**: - Each test case has a unique `Benchmark Definition` that is generated based on the randomly selected value between 1 and 52 (inclusive). - These definitions are used to execute specific code snippets, which may be optimized or unoptimized versions of the same logic. 4. **Latest Benchmark Result**: - The provided benchmark result data shows the performance statistics for each individual test case across different browsers and devices. - The `RawUAString` field contains metadata about the device running the benchmark (e.g., Chrome version, operating system), while other fields provide execution rates per second. Based on this analysis, it appears that the code is designed to generate a set of randomized test cases for benchmarking JavaScript performance under various conditions.
Related benchmarks:
new Array() vs Array.from() with random data
Array.find vs. Map.getss
Spread Operator VS Array.prototype.slice() VS Array.prototype.map()
Array.find vs. Map.get fork
Array.find vs. Map.get 2
Comments
Confirm delete:
Do you really want to delete benchmark?