Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
object lookup speed
(version: 0)
Comparing performance of:
without reference vs with reference
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
function getRandomIntInclusive(min, max) { min = Math.ceil(min); max = Math.floor(max); return Math.floor(Math.random() * (max - min + 1) + min); // The maximum is inclusive and the minimum is inclusive } function Skill(){ this.id = getRandomIntInclusive(1, 1000000); this.proficiency = getRandomIntInclusive(0, 10); } function makeSkill(n) { var skills = new Array(n) for (var i = 0; i < n; ++i) { skills[i] = new Skill() } return skills; } function Employee(){ this.age = getRandomIntInclusive(16, 75); this.id = getRandomIntInclusive(1, 1000000); this.skills = makeSkill(1000); } function makeEmployees(n) { var employees = new Array(n) for (var i = 0; i < n; ++i) { employees[i] = new Employee() } return employees } var e1 = makeEmployees(1000)
Tests:
without reference
var i = 1000; while (i--) { console.log(e1[i].skills[i]) console.log(e1[i].skills[i]) console.log(e1[i].skills[i]) console.log(e1[i].skills[i]) console.log(e1[i].skills[i]) console.log(e1[i].skills[i]) console.log(e1[i].skills[i]) console.log(e1[i].skills[i]) console.log(e1[i].skills[i]) console.log(e1[i].skills[i]) }
with reference
var i = 1000; while (i--) { let x = e1[0].skills console.log(x[i]) console.log(x[i]) console.log(x[i]) console.log(x[i]) console.log(x[i]) console.log(x[i]) console.log(x[i]) console.log(x[i]) console.log(x[i]) console.log(x[i]) }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
without reference
with reference
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):
Let's dive into the explanation of the provided benchmark. **Benchmark Definition** The benchmark is designed to measure the speed of object lookup in an array. The script generates two arrays: `skills` and `e1`. The `Skills` class has an instance variable `id` that is generated randomly, and another instance variable `proficiency` with a value between 0 and 10. The `makeSkill` function creates an array of `Skills` instances, and the `Employee` class has an instance variable `skills`, which is an array created by calling `makeSkill(1000)`. The `makeEmployees` function creates an array of `Employee` instances. **Options Compared** There are two test cases that compare the speed of object lookup: 1. **Without Reference**: In this case, the code uses a plain variable `x` to access the element in the `e1[0].skills` array using bracket notation (`x[i]`). The code logs 10 consecutive accesses to the same element. 2. **With Reference**: In this case, the code uses an object reference (`let x = e1[0].skills`) to access the element in the `e1[0].skills` array. Again, the code logs 10 consecutive accesses to the same element. **Pros and Cons** * **Without Reference**: + Pros: Uses less memory and is more efficient, as it avoids creating an object reference. + Cons: May be slower due to the overhead of bracket notation or array indexing. * **With Reference**: + Pros: Can be faster due to caching, which can reduce the number of lookups required. + Cons: Uses more memory and is less efficient, as it creates an object reference. **Other Considerations** The benchmark assumes that the browser has sufficient memory and CPU resources to execute the code efficiently. The results may vary depending on the specific browser and hardware configuration. **Library** None of the provided scripts use any external libraries. However, some browsers may have built-in optimizations or features that could affect the performance of the benchmark. **Special JS Feature/Syntax** The benchmark uses JavaScript's object notation syntax to access elements in arrays. It also uses the `let` keyword for variable declarations, which is a newer feature introduced in ECMAScript 2015. **Alternative Benchmarking Approaches** There are other approaches that could be used to benchmark object lookup speed, such as: * Using a more realistic data structure, like an object with nested properties. * Adding noise or variability to the input data to simulate real-world scenarios. * Measuring the performance of different optimization techniques, such as caching or lazy loading. These alternative approaches can provide more accurate and relevant results for certain use cases, but may add complexity to the benchmarking process.
Related benchmarks:
Fastest Partion of Arrays (heavy predicate)
Set.has v.s Array.includes
yoooooo
Set.has v.s Array.includes v2
Comments
Confirm delete:
Do you really want to delete benchmark?