with-vs-fn

JavaScript performance comparison

Test case created by

Preparation code

<script>
  locals = {
   name: "Matt",
   email: "wahoo@wahoo.com",
   phone: "(555) 555-5555"
  };
  
  
  keys = [];
  values = [];
  
  for (key in locals) {
   local = locals[key];
  
   keys.push(key);
   values.push(local);
  
  }
  
  keys = keys.join(',');
  
  function withwith() {
  
   with(locals) {
  
    var t = name + email + phone,
        y = phone + email + name,
        h = phone + name;
  
   }
  
  }
  
  fn = new Function(keys, "\
   var t = name + email + phone,\
       y = phone + email + name,\
       h = phone + name;\
  ");
</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
withwith();
pending…
fn
fn.apply(this, values);
pending…

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

Compare results of other browsers

1 Comment