Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Switch vs Object Literal Performance Check case 40
(version: 1)
Comparing performance of: Switch vs Object Literal
Comparing performance of:
switch case vs object literal
Created:
4 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var str = Math.floor(Math.random() * 40) + 1
Tests:
switch case
switch (str) { case 1: console.log('A'); break; case 2: console.log('B'); break; case 3: console.log('C'); break; case 4: console.log('C'); break; case 5: console.log('A'); break; case 6: console.log('B'); break; case 7: console.log('C'); break; case 8: console.log('C'); break; case 9: console.log('A'); break; case 10: console.log('B'); break; case 11: console.log('C'); break; case 12: console.log('C'); break; case 13: console.log('C'); break; case 14: console.log('C'); break; case 15: console.log('A'); break; case 16: console.log('B'); break; case 17: console.log('C'); break; case 18: console.log('C'); break; case 19: console.log('A'); break; case 20: console.log('B'); break; case 21: console.log('C'); break; case 22: console.log('C'); break; case 23: console.log('A'); break; case 24: console.log('B'); break; case 25: console.log('C'); break; case 26: console.log('C'); break; case 27: console.log('A'); break; case 28: console.log('B'); break; case 29: console.log('C'); break; case 30: console.log('C'); break; case 31: console.log('C'); break; case 32: console.log('C'); break; case 33: console.log('A'); break; case 34: console.log('B'); break; case 35: console.log('C'); break; case 36: console.log('C'); break; case 37: console.log('A'); break; case 38: console.log('B'); break; case 39: console.log('C'); break; case 40: console.log('C'); break; }
object literal
var objLiteral = { 1: function () { console.log('A'); }, 2: function () { console.log('B'); }, 3: function () { console.log('C'); }, 4: function () { console.log('A'); }, 5: function () { console.log('B'); }, 6: function () { console.log('C'); }, 7: function () { console.log('A'); }, 8: function () { console.log('B'); }, 9: function () { console.log('C'); }, 10: function () { console.log('C'); }, 11: function () { console.log('C'); }, 12: function () { console.log('C'); }, 13: function () { console.log('C'); }, 14: function () { console.log('C'); }, 15: function () { console.log('C'); }, 16: function () { console.log('C'); }, 17: function () { console.log('C'); }, 18: function () { console.log('C'); }, 19: function () { console.log('C'); }, 20: function () { console.log('C'); }, 21: function () { console.log('C'); }, 22: function () { console.log('C'); }, 23: function () { console.log('C'); }, 24: function () { console.log('C'); }, 25: function () { console.log('C'); }, 26: function () { console.log('C'); }, 27: function () { console.log('C'); }, 28: function () { console.log('C'); }, 29: function () { console.log('C'); }, 30: function () { console.log('C'); }, 31: function () { console.log('C'); }, 32: function () { console.log('C'); }, 33: function () { console.log('C'); }, 34: function () { console.log('C'); }, 35: function () { console.log('C'); }, 36: function () { console.log('C'); }, 37: function () { console.log('C'); }, 38: function () { console.log('C'); }, 39: function () { console.log('C'); }, 40: function () { console.log('C'); }, }; objLiteral[str]();
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
switch case
object 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):
To answer this question, I would need to know the specific details about the code that is being executed in the context of these benchmark results. However, based on the information provided, it appears that there are two test cases: 1. "switch case" - This suggests a test case for a switch statement or a similar construct. 2. "object literal " - This suggests a test case for creating an object literal, which is an object defined with key-value pairs. The benchmark results show the execution time per second for each test case. In this case, the execution times are: * "switch case": 147454.8125 executions/second * "object literal ": 146470.921875 executions/second Based on the code snippet provided earlier, it appears that the object literal is being used to define a switch statement with multiple cases. The `objLiteral[str]` syntax suggests that the string value will be used as a key in the object literal. To answer the question, I would need more information about the specific requirements or constraints of the code that is being executed. However, based on the provided benchmark results, it appears that creating an object literal with a large number of cases (in this case, 40) may be slower than executing a switch statement with multiple cases. If you could provide more context or clarify what the question is asking, I would be happy to try and assist further.
Related benchmarks:
Math.floor vs bitwise <<
floor() vs trunc() vs bitwise hacks (~~, >> 0, etc) 2
Math.floor vs Math.trunc
Math.floor(Math.random() * 1000000000).toString() vs window.performance.now().toFixed()
Math.floor vs alternatives 2
Comments
Confirm delete:
Do you really want to delete benchmark?