そして、コンパイルした方が早いのか確認するためのベンチマークツールを作ってみました。
チェックツールは以下から利用できます。
[JavaScript] ベンチマークツール - ログろいど
なんと、Firefox、Chromeではコンパイルした方が遅い。
Firefoxでは、コンパイルした場合と、しない場合の差は大きくないが、Chromeでは大きな差が出ました。
ちなみに、Firefoxで指定しているJavaScript JITコンパイラは JaegerMonkey。
私の実行環境はこんな感じ。
OS | Windows 7 Professional Service Pack 1 32bit |
---|---|
CPU | Intel Core i5 M 560 2.67GHz |
RAM | 2GB |
パターン1
1 2 | "hogehogehogehogehoge" .replace(/h/g, "H" ); "hogehogehogehogehoge" .replace(/h/g, "H" ); |
1 2 3 4 | var r= new RegExp(); r.compile( "h" , "g" ); "hogehogehogehogehoge" .replace(r, "H" ); "hogehogehogehogehoge" .replace(r, "H" ); |
1 2 3 4 5 6 7 8 9 10 | "hogehogehogehogehoge" .replace(/h/g, "H" ); "hogehogehogehogehoge" .replace(/h/g, "H" ); "hogehogehogehogehoge" .replace(/h/g, "H" ); "hogehogehogehogehoge" .replace(/h/g, "H" ); "hogehogehogehogehoge" .replace(/h/g, "H" ); "hogehogehogehogehoge" .replace(/h/g, "H" ); "hogehogehogehogehoge" .replace(/h/g, "H" ); "hogehogehogehogehoge" .replace(/h/g, "H" ); "hogehogehogehogehoge" .replace(/h/g, "H" ); "hogehogehogehogehoge" .replace(/h/g, "H" ); |
1 2 3 4 5 6 7 8 9 10 11 12 | var r= new RegExp(); r.compile( "h" , "g" ); "hogehogehogehogehoge" .replace(r, "H" ); "hogehogehogehogehoge" .replace(r, "H" ); "hogehogehogehogehoge" .replace(r, "H" ); "hogehogehogehogehoge" .replace(r, "H" ); "hogehogehogehogehoge" .replace(r, "H" ); "hogehogehogehogehoge" .replace(r, "H" ); "hogehogehogehogehoge" .replace(r, "H" ); "hogehogehogehogehoge" .replace(r, "H" ); "hogehogehogehogehoge" .replace(r, "H" ); "hogehogehogehogehoge" .replace(r, "H" ); |
- Mozilla Firefox 14,15,16.17
- Google Chrome 21
- Windows Internet Explorer 9
皆さんもチェックツールの結果をお教えください。
以下のリンクを開くと、上記のテストコードが入力された状態で開きます。
[JavaScript] ベンチマークツール - ログろいど
JavaScript
0 件のコメント:
コメントを投稿