function vs new Function

Benchmark created on


Preparation HTML

<script>
  var foo = function(a, b) {
   a = a.toString();
   b = b.toString();
   if (a === b) {
    return 0;
   }
  
   return (a < b) ? -1 : 1;
  };
  var bar = new Function("a", "b", "a = a.toString(); b = b.toString(); if (a === b) { return 0; } return (a < b) ? -1 : 1;");
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
foo
foo(1000, 2000);
ready
bar
bar(1000, 2000);
ready

Revisions

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