Anonymous Function Speed Execution Test

Benchmark created on


Description

How fast are anonymous functions compared to declaritive

Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<p class="result"></p>

Setup

var arr = [{
      pretext: "hello",
      subtext: "world"
    }, {
      pretext: "hello",
      subtext: "world"
    }, {
      pretext: "hello1",
      subtext: "world1"
    }];

Test runner

Ready to run.

Testing in
TestOps/sec
Anonymous
var value = (function(arr, val) {
  for (var i = 0, len = arr.length; i < len; i++) {
    if (arr[i].subtext === val) {
      return arr[i].pretext;
    }
  }
})(arr, "world1");
$('.result').text(value);
ready
Declarive
var value = function(arr, val) {
  for (var i = 0, len = arr.length; i < len; i++) {
    if (arr[i].subtext === val) {
      return arr[i].pretext;
    }
  }
};
value = value(arr, "world1");
$('.result').text(value);
ready

Revisions

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