allocate local variable vs counting .length each time

Benchmark created by J3QQ4-H7H2V-2HCH4-M3HK8-6M8VW on


Preparation HTML

<html></html>

Test runner

Ready to run.

Testing in
TestOps/sec
Allocate var each cycle
var values = ["123", "456", "789"];
var valuesCount = values.length;
for (var i = 0; i < valuesCount; i++) {
    var x = values[i]; //do nothing
}
ready
Count length each time
var values = ["123", "456", "789"];
for (var i = 0; i < values.length; i++) {
    var x = values[i]; //do nothing
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

  • Revision 1: published by J3QQ4-H7H2V-2HCH4-M3HK8-6M8VW on