var a=123,b=123,c=123;
this.d=this.e=this.f=123;
for (let i = 0; i < 100; i++) {
a + b + c + i;
}
for (let i = 0; i < 100; i++) {
this.d + this.e + this.f + i;
}
for (let i = 0; i < 100; i++) {
window.d + window.e + window.f + i;
}
for (let i = 0; i < 100; i++) {
this.a + this.b + this.c + i;
}
for (let i = 0; i < 100; i++) {
window.a + window.b + window.c + i;
}
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
variable | |
this.property | |
window.property | |
this.variable | |
window.variable |
Test name | Executions per second |
---|---|
variable | 27012.5 Ops/sec |
this.property | 2332194.2 Ops/sec |
window.property | 4198.2 Ops/sec |
this.variable | 2454662.2 Ops/sec |
window.variable | 4477.8 Ops/sec |
Let's dive into the world of JavaScript microbenchmarks on MeasureThat.net.
Benchmark Definition:
The benchmark definition is provided in JSON format, which defines two approaches for comparing variables and properties:
var vs property (var vs this.property)
: This approach compares the performance of using a traditional variable (var
) versus an object property (this.property
).variable vs property (this.variable vs window.property)
: This approach compares the performance of accessing variables directly (using dot notation) versus accessing properties on the window
object (using dot notation).Options being compared:
The benchmark compares two options:
var
) to store and access values.this.property
or window.property
) to store and access values.Pros and Cons of each approach:
var
):this.property
or window.property
):window
object).Library usage:
There is no explicit library mentioned in the benchmark definition. However, the this
keyword is used to access object properties, which implies the use of a JavaScript engine's built-in functionality. If we consider libraries like Lodash or Underscore.js that might be used for utility functions, there are none explicitly mentioned.
Special JS feature or syntax:
There is no special JavaScript feature or syntax being tested in this benchmark. The focus is on comparing two approaches: using traditional variables versus object properties.
Alternative approaches:
Other approaches to compare variable and property usage could include:
These alternatives might provide additional insights into the trade-offs between different approaches, but they are not explored in this specific benchmark.