for vs each, hash vs array
JavaScript performance comparison
Preparation code
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
var hash = {
key1: 'value1',
key2: 'value2',
key3: 'value3'
};
var array = [
{
key: 'key1',
value: 'value1'},
{
key: 'key2',
value: 'value2'},
{
key: 'key3',
value: 'value3'}];
</script>
Preparation code output
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
hash -> for |
|
pending… |
hash -> each |
|
pending… |
array -> for |
|
pending… |
array -> each |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments