Access via global vs jQuery data vs closure

Benchmark created by Scott Sauyet on


Preparation HTML

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


<script>
  //====================================================================
  
  var arr1 = [1, 2, 3], x1;
  var globalAccess = function() {
      x1 = arr1;
  };
  
  //====================================================================
  
  var arr2 = [1, 2, 3], x2;
  jQuery(document).ready(function() {
      jQuery(document.body).data("arr", arr2);
  });
  var jQueryDataAccess = function() {
      x2 = jQuery(document.body).data("arr");
  };
  
  //====================================================================
  
  var MYAPP = MYAPP || {};
  (function() {
      var arr3 = [1, 2, 3];
      MYAPP.closureAccess = function() {
          MYAPP.x3 = arr3;
      };
  }());
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Global Access
globalAccess();
ready
JQuery Data Access
jQueryDataAccess()
ready
Closure Access
MYAPP.closureAccess();
ready

Revisions

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

  • Revision 1: published by Scott Sauyet on