fn.call(何か) ベンチ
気になったのでとってみたけどあまり意味が無いベンチになりました。fn.call(null) って速いのね。
Browser | fn.call(null) | fn.call(this) | fn.call(window) | (function(){fn()} |
Fx3.6 | 1162 | 5911 | 3630 | 6432 |
IE8 | 937 | 1010 | 1073 | 2338 |
IE6 | 2833 | 2447 | 2578 | 5093 |
GC6 | 304 | 285 | 1452 | 403 |
Sa5 | 288 | 323 | 280 | 2002 |
iSa4 | 69 | 67 | 65 | 300 |
Op10.6x | 1916 | 1970 | 4066 | 2287 |
Total | 7509 | 12013 | 13144 | 18855 |
bench.js は http://pigs.sourceforge.jp/blog/20100722 にあります
<!DOCTYPE html><html lang="ja"><head><meta charset="utf-8" /> <title>bench: call(hoge)</title> <style>th,td { padding: 5px; text-align: right }</style> <script src="bench.js"></script><script> window.onload = function() { document.body.innerHTML += "<p>" + navigator.userAgent + "</p>Running..."; var loop = getLoop(); // --------------------------------------------------------- var _ary = [0, 1, 2, 3, 4]; function callback(value, index) { return index * value; } function _call_null(idx) { var ary = _ary, i = 0, iz = ary.length; for (; i < iz; ++i) { callback.call(null, ary[i], i); } return idx; } function _call_this(idx) { var ary = _ary, i = 0, iz = ary.length; for (; i < iz; ++i) { callback.call(this, ary[i], i); } return idx; } function _call_window(idx) { var ary = _ary, i = 0, iz = ary.length; for (; i < iz; ++i) { callback.call(window, ary[i], i); } return idx; } function _func(idx) { var ary = _ary, i = 0, iz = ary.length; for (; i < iz; ++i) { (function(value, index) { callback(value, index); })(ary[i], i); } return idx; } job(5, loop, ["callback.call(null)", _call_null, "callback.call(this)", _call_this, "callback.call(window)", _call_window, "(function(){callback()}", _func]); } </script></head><body></body></html>