Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
object Array Test
(version: 0)
Comparing performance of:
keys vs reduce vs for..in vs entries
Created:
2 years ago
by:
Guest
Jump to the latest result
Tests:
keys
const testObj = { '10:00': 1, '11:00': 20, '12:00': 30, '13:00': 2, '14:00': 40, '15:00': 30, '16:00': 5, '17:00': 50, '18:00': 60, '19:00': 70, '20:00': 7, '21:00': 80, '22:00': 8, '23:00': 38, '24:00': 21, '25:00': 40, '26:00': 51, '27:00': 62, '28:00': 72, '29:00': 31, '30:00': 41, '31:00': 51, '32:00': 64, '33:00': 74, '34:00': 84, '35:00': 36, '36:00': 76, '37:00': 38, '38:00': 48, '39:00': 58, '40:00': 68, '41:00': 88, '42:00': 17, '43:00': 27, '44:00': 37, '45:00': 57, '46:00': 67, '47:00': 77, '48:00': 87, '49:00': 97, } const list = Object.keys(testObj).map(key => ({name: key, number: testObj[key]})); console.log(list)
reduce
const testObj = { '10:00': 1, '11:00': 20, '12:00': 30, '13:00': 2, '14:00': 40, '15:00': 30, '16:00': 5, '17:00': 50, '18:00': 60, '19:00': 70, '20:00': 7, '21:00': 80, '22:00': 8, '23:00': 38, '24:00': 21, '25:00': 40, '26:00': 51, '27:00': 62, '28:00': 72, '29:00': 31, '30:00': 41, '31:00': 51, '32:00': 64, '33:00': 74, '34:00': 84, '35:00': 36, '36:00': 76, '37:00': 38, '38:00': 48, '39:00': 58, '40:00': 68, '41:00': 88, '42:00': 17, '43:00': 27, '44:00': 37, '45:00': 57, '46:00': 67, '47:00': 77, '48:00': 87, '49:00': 97, } const list = Object.keys(testObj).reduce((acc, curr) => { return [...acc, {name: curr, number: testObj[curr] }] }, []) console.log(list)
for..in
const testObj = { '10:00': 1, '11:00': 20, '12:00': 30, '13:00': 2, '14:00': 40, '15:00': 30, '16:00': 5, '17:00': 50, '18:00': 60, '19:00': 70, '20:00': 7, '21:00': 80, '22:00': 8, '23:00': 38, '24:00': 21, '25:00': 40, '26:00': 51, '27:00': 62, '28:00': 72, '29:00': 31, '30:00': 41, '31:00': 51, '32:00': 64, '33:00': 74, '34:00': 84, '35:00': 36, '36:00': 76, '37:00': 38, '38:00': 48, '39:00': 58, '40:00': 68, '41:00': 88, '42:00': 17, '43:00': 27, '44:00': 37, '45:00': 57, '46:00': 67, '47:00': 77, '48:00': 87, '49:00': 97, } let arr =[]; for(let i in testObj) { arr.push({ name: i, number: testObj[i] }); } console.log(arr)
entries
const testObj = { '10:00': 1, '11:00': 20, '12:00': 30, '13:00': 2, '14:00': 40, '15:00': 30, '16:00': 5, '17:00': 50, '18:00': 60, '19:00': 70, '20:00': 7, '21:00': 80, '22:00': 8, '23:00': 38, '24:00': 21, '25:00': 40, '26:00': 51, '27:00': 62, '28:00': 72, '29:00': 31, '30:00': 41, '31:00': 51, '32:00': 64, '33:00': 74, '34:00': 84, '35:00': 36, '36:00': 76, '37:00': 38, '38:00': 48, '39:00': 58, '40:00': 68, '41:00': 88, '42:00': 17, '43:00': 27, '44:00': 37, '45:00': 57, '46:00': 67, '47:00': 77, '48:00': 87, '49:00': 97, } const list = Object.entries(testObj).map(([name, number]) => ({ name: name, number})); console.log(list)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
keys
reduce
for..in
entries
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):
It looks like you want me to analyze the benchmark results and provide some insights. From the latest benchmark result, we can see that: * The `entries` test has an average execution time of around 64760 seconds per second, which is relatively low compared to other tests (e.g., `for..in` at 66203 seconds/second). * This suggests that the `entries` method in JavaScript's Object prototype might be quite efficient, especially when compared to iterating over a list using traditional indexing (`for..in`). However, without knowing more about the specific use case or implementation details of this code, it's difficult to provide any further insights. Could you please provide more context or information about what you're trying to achieve with these benchmark results?
Related benchmarks:
access
isArray Test
asados
39ut983u4t983h93uz
Array isArray vs Object.prototype
Comments
Confirm delete:
Do you really want to delete benchmark?