Global Variables vs Local Variables (v49)

Revision 49 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 x() {
    return Object.create(null);
  }
  function y() {
    return {};<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Global variables
x();
ready
Local variables
y();
ready
Cached global variables
 
ready

Revisions

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