http://webos-goodies.jp/archives/51166928.html
配列が束縛する変数のスコープによって差が出るんじゃないかな…と思って、IEで試してみるけど、あんまり変わらず。うーん。
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Microsoft Internet Explorer
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
total: 106078 [ms]
-
- -
name: local(direct)
%: 23.686344011010764
count: 5
ms: 25126
ms/call: 5025.2
-
- -
name: local -> local
%: 26.33533814740097
count: 5
ms: 27936
ms/call: 5587.2
-
- -
name: global(direct)
%: 24.701634646203736
count: 5
ms: 26203
ms/call: 5240.6
-
- -
name: global -> local
%: 25.276683195384532
count: 5
ms: 26813
ms/call: 5362.6
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
OK
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
テストコードは以下の通り。
<html> <head> <title>TEST</title> <script type="text/javascript" src="profiler.js"></script> <script> var global_array = new Array(1000000); function sample_local() { var local_array = new Array(1000000); var out = new Array(); for (var i = 0; i < local_array.length; i++) { out.push(i); } } function sample_local_local() { var local_array = new Array(1000000); var len = local_array.length; var out = new Array(); for (var i = 0; i < len; i++) { out.push(i); } } function sample_global() { var out = new Array(); for (var i = 0; i < global_array.length; i++) { out.push(i); } } function sample_globa_local() { var len = global_array.length; var out = new Array(); for (var i = 0; i < len; i++) { out.push(i); } } function run_test() { for(var i = 0; i < 5; i++) { Profiler.profile('local(direct)', sample_local); Profiler.profile('local -> local', sample_local_local); Profiler.profile('global(direct)', sample_global); Profiler.profile('global -> local', sample_globa_local); } Profiler.report(); } </script> </head> <body> <input type="button" value="テスト" onclick="run_test();"> </body> </html>