var array = []
var object1 = {}
var object2 = {}
for(var i = 0; i < 1e6; i++) {
var v = Math.random()
array[i] = v
object1[i] = v
object2[`v${i}`] = v
}
var sum = 0
for(var i = 1e6 - 1; i >= 0; i--) {
sum += array[i]
}
sum
var sum = 0
for(var i = 1e6 - 1; i >= 0; i--) {
sum += object1[i]
}
sum
var sum = 0
for(var i = 1e6 - 1; i >= 0; i--) {
sum += object2[`v${i}`]
}
sum
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
array | |
object | |
object with text field |
Test name | Executions per second |
---|---|
array | 14.1 Ops/sec |
object | 11.7 Ops/sec |
object with text field | 1.9 Ops/sec |
The provided JSON represents a JavaScript microbenchmarking test case created using MeasureThat.net. Let's break down what is tested, the options compared, and their pros and cons.
What is being tested?
Three individual test cases are defined:
array
: Measures the execution time of accessing an element in an array.object
: Measures the execution time of accessing an element in a JavaScript object (i.e., an object literal).object with text field
: Measures the execution time of accessing an element in a JavaScript object with a dynamically generated property name.Options compared
The three test cases compare different approaches to accessing elements in arrays and objects:
array
uses direct array indexing (array[i]
)object
uses dot notation (object1[i]
)object with text field
uses bracket notation with dynamic property names (object2[
v${i}]
)Pros and cons of each approach
n
.Library usage
None of the test cases use any external libraries. However, it's worth noting that some JavaScript objects (e.g., Array
) are built-in and do not require any additional libraries to function.
Special JS features or syntax
There doesn't seem to be any special JavaScript features or syntax being tested in these benchmarking test cases. The code uses basic JavaScript constructs like loops, arrays, objects, and arithmetic operations.
Alternatives
Other alternatives for benchmarking similar scenarios might include:
These alternatives might offer additional features, flexibility, or scalability compared to MeasureThat.net's simple and straightforward approach.