Create namespace

JavaScript performance comparison

Revision 2 of this test case created by Cezary Tomczyk

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var namespacecreated;
  
  var _createNamespaceForEach = function(name, separator, container) {
  
      ns = name.split(separator || '.');
      o = container || window;
  
      ns.map(function(item) {
        o = o[item] = o[item] || {};
      });
      return o;
      };
  var _createNamespace = function(name, separator, container) {
      ns = name.split(separator || '.');
      o = container || window;
  
      for (i = 0, len = ns.length; i < len; i++) {
        o = o[ns[i]] = o[ns[i]] || {};
      }
      return o;
      };

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
with forEach
namespacecreated = _createNamespaceForEach('Mytest.long.namespaced.obj.testing');
pending…
without forEach
namespacecreated = _createNamespace('Mytest.long.namespaced.obj.testing');
pending…

Compare results of other browsers

Revisions

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

0 Comments