æè¿
ã¾ããã¦ããJavaScript ã®ãã³ããã¼ã¯ãåããªããã°ãªããªãä»äºãæ¥ãã®ã§ã
ãã¼ã«ããã¬ã¤ã«ãã¾ããã
ãããå
¬éãã¾ãã(ãã¦ã³ãã¼ãã¯ä¸çªä¸ã«ããã¾ãã)
使ãæ¹
script ã¿ã°ã§ benchmark.js ãèªã¿è¾¼ãã§ã以ä¸ã®ããã«é£æ³é åã®é¢æ°ç¾¤ã渡ãã ãã§ãã
benchmark({ 'ã»ãã»ãã®è¨æ¸¬': function() { ...... }, 'ãµããµãã®å¦çã®è¨æ¸¬': function() { ...... } });
çµæã¯ä»¥ä¸ã®ããã«è¡¨ç¤ºããã¾ãã
*** ã»ãã»ãã®è¨æ¸¬ *** result : 0.0011[ms] *** ãµããµãã®å¦çã®è¨æ¸¬ *** result : 0.111[ms]
表示ãããç§æ°ã¯
é¢æ°ã®ä¸èº«ãä¸åã ãå®è¡ããæéã§ãã
é¢æ°å¼ã³åºãã®ã³ã¹ãã¯å·®ãå¼ããã¦ãã¾ãã
ã¾ããFireBug ã使ã£ã¦ããå ´åã¯
benchmark.at('firebug')({ ...... });
ã¨ãããã¨ã§ããã°ã FireBug ã®ã³ã³ã½ã¼ã«ã«è¡¨ç¤ºã§ãã¾ãã
注æç¹ï¼ãããå®ããªãã¨æ£ç¢ºãªãã³ããã¼ã¯ãåãã¾ããï¼
1. è¨æ¸¬ã¯ãã°ãã¼ãã«é åã§è¡ã£ã¦ãã ããã
é¢æ°å®ç¾©ç®æã®ã¹ã³ã¼ãã«ãã£ã¦ãé¢æ°ã®éããå¤ããããã
ãã¡ãªä¾
function() { benchmark({ ... }); }
2. 軽ãããé¢æ°ãå ¥ãã¦è¨æ¸¬ãã¦ããæ£ç¢ºãªå¤ã¯åºã¾ãã
誤差ã«ãã£ã¦ããã¤ãã¹ã®å¤ãè¨æ¸¬ãããå¯è½æ§ãããã¾ãã
benchmark({ 'æªãä¾': function() { i++; }, 'è¯ãä¾': function() { i++;i++;i++;i++;i++;......(10000åãããæ¸ã) } });
ã¡ãªã¿ã«
ã°ãã¼ãã«ã¯ benchmark ã¨ããé¢æ°ããæ±æãã¦ãã¾ããã
ä»ã®ã©ã¤ãã©ãªã¨ãã£ããã«ä½¿ã£ã¦ã大ä¸å¤«ã§ãã