Editing Angular vs. jQuery vs. Native This edit will create a new revision. Your details (optional) Name Email (won’t be displayed; might be used for Gravatar) URL Test case details Title * Published (uncheck if you want to fiddle around before making the page public) Description (in case you feel further explanation is needed)(Markdown syntax is allowed) Comparison study for how an MVC framework vs. jQuery vs. native code 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. jquery-only vs. angular.js scenarios. Are you a spammer? (just answer the question) Preparation code Preparation code HTML (this will be inserted in the <body> of a valid HTML5 document in standards mode) (useful when testing DOM operations or including libraries) <!-- Jquery --> <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> jQuery: <div id="jq_test"></div> <script type="text/javascript"> var jqEl = $('#jq_test'); var children = ''; var jqPush = function (data) { children += '<span>' + data + '</span>'; } var jqRender = function () { jqEl.append(children); //jqEl.append('<span>' + data + '</span>'); } var jqClear = function () { jqEl.empty(); children = ''; // not sure if we need to do more to prevent memory leak - probably doesn't matter } </script> <!-- Angular --> <div ng-app> Angular: <div ng-controller="Ctrl" id="angList"><span ng-repeat="item in data">{{item}}</span></div> </div> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.1.3/angular.min.js"></script> <script type="text/javascript"> 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); // angScope.$digest(); }; window.angularPush = function(data){ angScope.data.push(data); // angScope.$digest(); }; window.angularApply = function(data){ angScope.$apply(); }; }); </script> <!-- Native --> <div id="native_test"></div> <script type="text/javascript"> var nativeEl = document.getElementById('native_test'); var nativeRender = function (data) { var el = document.createElement('span'); el.innerHTML = data; nativeEl.appendChild(el); } var nativeClear = function () { while (nativeEl.hasChildNodes()) { nativeEl.removeChild(nativeEl.lastChild); } // not sure if we need to do more to prevent memory leak - probably doesn't matter } </script> Include JavaScript libraries as follows: <script src="//cdn.ext/library.js"></script> Define setup for all tests (variables, functions, arrays or other objects that will be used in the tests) (runs before each clocked test loop, outside of the timed code region) (e.g. define local test variables, reset global variables, clear canvas, etc.) (see FAQ) Define teardown for all tests (runs after each clocked test loop, outside of the timed code region) (see FAQ) Code snippets to compare Test 1 Title Async (check if this is an asynchronous test) Code jqClear(); for (var i = 0; i < 100; i++) { jqPush('jq-item'); } jqRender(); Test 2 Title Async (check if this is an asynchronous test) Code angularClear(); for (var i = 0; i < 100; i++) { angularPush('ng-item'); } angularApply(); Test 3 Title Async (check if this is an asynchronous test) Code nativeClear(); for (var i = 0; i < 100; i++) { nativeRender('native-item'); }