Global Variables vs Local Variables (v51)

Revision 51 of this benchmark created by Sean on


Description

This test compares the performance of global variables to local variables within functions.

Global variables should be slower because they do not exist in a function's activation object. JavaScript must traverse the Scope Chain to locate global variables.

Preparation HTML

<script>

  function objectCreate() {
    return Object.create(null);
  }
  function objectLiteral() {
    return {};
  }
  function objectNew() {
    return new Object;
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Object.create
objectCreate();
ready
Object Literal
objectLiteral();
ready
Object New
objectNew();
ready

Revisions

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