Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
FAQ
Register
Log In
Run results for:
Local scope vs outer scope variables
Cache variable in the function scope
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:120.0) Gecko/20100101 Firefox/120.0
Browser:
Firefox 120
Operating system:
Linux
Device Platform:
Desktop
Date tested:
2 years ago
Benchmark engine:
Benchmark.js
Do not cache at all
18.1M/s
Cache in the inner scope
16.5M/s
View exact numbers
Test name
Executions per second
✓
Do not cache at all
18,144,520 Ops/sec
Cache in the inner scope
16,545,535 Ops/sec
Script Preparation code:
var testVar = 10;
Tests:
Cache in the inner scope
function doTest1(){ var sum = 0; for (var i = 0; i < testVar; i++){ sum = sum + i; } } doTest1();
Do not cache at all
function doTest2(){ var sum = 0; var testVarLocal = testVar; for (var i = 0; i < testVarLocal; i++){ sum = sum + i; } } doTest2();