Random Tests (v10)

Revision 10 of this benchmark created by Nicholas on


Description

Random performance tests for on the fly testing.

Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js">
</script>

<sc<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js">
</script>

<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>ript src="https://code.jquery.com/jquery-2.1.3.min.js"></script>

Setup

var testArray = [];
    
    for (var i = 0; i < 10000; i++) {
      testArray.push(i);
    }
    
    function test_for() {
      for (var i = 0; i < testArray.length; i++) {
        testInLoop(testArray[i]);
      }
    }
    
    function test_for_in() {
      for (var val in testArray) {
        testInLoop(val);
      }
    }
    
    function test_for_each() {
      testArray.forEach(function(val) {
        testInLoop(val);
      });
    }
    
    function test_angular_for_each() {
      angular.forEach(testArray, function(val) {
        testInLoop(val);
      });
    }
    
    function test_jquery_each() {
      $.each(testArray, function(i, val) {
        testInLoop(val);
      });
    }
    
    function testInLoop(val) {
      return (val * val);
    }

Test runner

Ready to run.

Testing in
TestOps/sec
For
test_for();
ready
For In
test_for_in();
ready
array forEach
test_for_each();
ready
angular forEach
test_angular_for_each();
ready
jquery each
test_jquery_each();
ready

Revisions

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

  • Revision 6: published by Nicholas on
  • Revision 7: published by Nicholas on
  • Revision 10: published by Nicholas on