Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8">
    <title></title>
    <script type="text/javascript">
      (function(){
        
        var o1 = {
          o2: {
            o3: {
              o41: 1,
              o42: 2
            }
          }
        };
        
        function runTest(iterations, name, code)
        {
          var t = new Date();
          for (var i=iterations; i--; )
            code();
          return name + ": " + (new Date() - t) + "ms";
        }
        
        function runTests()
        {
          var lim = 5000000;
          var tests = [
            function() { 
              return runTest(lim, "direct", function() {
                o1.o2.o3.o41 += o1.o2.o3.o42;
              }) 
            },
            function() { 
              var o = o1.o2.o3;
              return runTest(lim, "aliased", function() {
                o.o41+= o.o42;
              })
            },
            function() {       
              with (o1.o2.o3)
              return runTest(lim, "with", function() {
                o41 += o42;
              })
            }
          ];
          
          var results = [];
          var i = 0;
          setTimeout(function slowLoop()
          {
             if ( i >= tests.length )
             {
               document.getElementById("results").innerHTML = results.join("<br>");
               return;
             }
             
             results[i] = tests[i++]();
             setTimeout(slowLoop, 10);
          }, 10);
          
        }
        
        window.onload = runTests;      
      })();
    </script>
  </head>
  <body>
    <div id="results"></div>
  </body>
</html>
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers