performance testing of named or anonymous functions (v21)

Revision 21 of this benchmark created on


Description

a small comparision betwean named function and function declaration

Preparation HTML

<script>
a = 1;
x = [];
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
anonymous
"use strict";
var a;
for (var i = 0; i < 10000; ++i) {
  x[i] = function() {a=a==1?a=0:a=1;};
  x[i]();
}
ready
function named expression
"use strict";
var a;
myEventHandler = function named() {
  a=a==1?a=0:a=1;
}

for (var i = 0; i < 10000; ++i) {
  x[i] = myEventHandler;
  x[i]();
}
ready
function declaration
"use strict";

var a;

function myEventHandler2() {
  a=a==1?a=0:a=1;
}

for (var i = 0; i < 10000; ++i) {
  x[i] = myEventHandler2;
  x[i]();
}
ready
name declared anonymous
"use strict";
var a;
for (var i = 0; i < 10000; ++i) {
  x[i] = function namaste() {a=a==1?a=0:a=1;};
  x[i]();
}
ready

Revisions

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