Angular vs. jQuery vs. Native vs. Native add item after item (v33)

Revision 33 of this benchmark created on


Description

Comparison study for how an MVC framework vs. jQuery vs. native code vs. querySelector performs while rendering a list populated from an array. We're doing a study trying to determine the best JavaScript approach to an app running on an ARM board, so we want to get a sense of what we're sacrificing in native js vs. newer native js vs. jquery-only vs. angular.js scenarios.

Preparation HTML

<!-- Jquery -->
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<h1>jQuery:</h1>
<div id="jq_test"></div>

<script>
var MAX = 50, index = 0, counter = 0;
var jqEl = $('#jq_test');
var children = '';
var jqPush = function (data) {
  children += '<span>' + data + '</span>';
  jqRender();
}
var jqRender = function () {
  jqEl.append(children);
  //jqEl.append('<span>' + data + '</span>');
} 
var jqClear = function () {
  jqEl.empty();
  children = '';
}
</script>

<!-- Angular -->
<div ng-app>
  <h1>Angular:</h1>
  <div ng-controller="Ctrl" id="angList"><span ng-repeat="item in data" ng-bind="item"></span></div>
</div>

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

<script>
  var Ctrl = function($scope){
    $scope.data = [];
  }
  angular.element(document).ready(function() {
    var angScope = $('#angList').scope();
    
    window.angularClear = function(){
      angScope.data.splice(0, angScope.data.length);
    };
    window.angularPush = function(data){
      angScope.data.push(data);
    };
  });
</script> 

<!-- Native -->
<h1>Native (getElementById):</h1>
<div id="native_test"></div>

<script>
var nativeEl = document.getElementById('native_test');
var nativeChildren = '';
var nativePush = function (data) {
  var el = '<span>' + data + '</span>';
  nativeChildren += el;
  nativeRender();
}
var nativeRender = function () {
  nativeEl.innerHTML = nativeChildren;
}
var nativeClear = function () {
  nativeEl.innerHTML = "";
  nativeChildren = null;
  nativeChildren = '';
}


</script> 
<!--Ember to come later -->

Test runner

Ready to run.

Testing in
TestOps/sec
jQuery 100
jqClear();
for (var i = 0; i < 100; i++) {
  jqPush('jq-item');
}
ready
Angular 100
angularClear();
for (var i = 0; i < 100; i++) {
  angularPush('ng-item');
}
ready
Native 100
nativeClear();
for (var i = 0; i < 100; i++) {
  nativePush('native-item');
}
 
ready
New Native 100
 
ready

Revisions

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