Arguments.length vs === undefined

Benchmark created by voloko on


Preparation HTML

<script>
  function prop1(obj, key, value) {
    if (arguments.length > 2) {
      obj[key] = value;
    } else {
      return obj[key];
    }
  }
  
  function prop2(obj, key, value) {
    if (value === undefined) {
      obj[key] = value;
    } else {
      return obj[key];
    }
  }
  
  var obj = {};
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
arguments.length
prop1(obj, 'foo', 'bar');
prop1(obj, 'foo');
ready
=== undefined
prop2(obj, 'foo', 'bar');
prop2(obj, 'foo');
ready

Revisions

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

  • Revision 1: published by voloko on