Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
反復処理に速さを求めて
Search
camcam_lemon
March 22, 2019
Programming
1
160
反復処理に速さを求めて
We Are JavaScripters @30thの登壇資料になります。
camcam_lemon
March 22, 2019
Tweet
Share
More Decks by camcam_lemon
See All by camcam_lemon
オレを実装してデザイン実装楽したい
lemon
0
57
要素のサイズを変えずに押しやすくする
lemon
0
75
iOSのキーボード入力ビューをカスタマイズする
lemon
0
260
視え方と文字の大きさ
lemon
1
410
Yarn WorkSpaces × React Nativeの環境構築
lemon
0
290
フロントエンドにおけるアーキテクチャとの向き合い方
lemon
10
5k
UI/UXデザイナーがデザインしてるもの
lemon
2
320
react-reduxで追加されたHooks APIの良い所と使い方
lemon
5
1k
ESLintで始めるTypeScriptの静的解析
lemon
8
2.1k
Other Decks in Programming
See All in Programming
bootcamp2025_バックエンド研修_WebAPIサーバ作成.pdf
geniee_inc
0
110
One Enishi After Another
snoozer05
PRO
0
100
ソフトウェア設計の実践的な考え方
masuda220
PRO
4
590
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
410
Six and a half ridiculous things to do with Quarkus
hollycummins
0
180
組込みだけじゃない!TinyGo で始める無料クラウド開発入門
otakakot
0
290
品質ワークショップをやってみた
nealle
0
490
エンジニアインターン「Treasure」とHonoの2年、そして未来へ / Our Journey with Hono Two Years at Treasure and Beyond
carta_engineering
0
290
monorepo の Go テストをはやくした〜い!~最小の依存解決への道のり~ / faster-testing-of-monorepos
convto
2
500
NixOS + Kubernetesで構築する自宅サーバーのすべて
ichi_h3
0
980
理論と実務のギャップを超える
eycjur
0
140
いま中途半端なSwift 6対応をするより、Default ActorやApproachable Concurrencyを有効にしてからでいいんじゃない?
yimajo
2
430
Featured
See All Featured
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.5k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
657
61k
Into the Great Unknown - MozCon
thekraken
40
2.1k
Why You Should Never Use an ORM
jnunemaker
PRO
59
9.6k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
127
53k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
132
19k
Building a Scalable Design System with Sketch
lauravandoore
463
33k
4 Signs Your Business is Dying
shpigford
185
22k
Learning to Love Humans: Emotional Interface Design
aarron
274
41k
The Power of CSS Pseudo Elements
geoffreycrofte
79
6k
Mobile First: as difficult as doing things right
swwweet
225
10k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
1.6k
Transcript
反復処理に速さを求めて We Are JavaScripters @30th
None
None
他にも色々な書き方がありますよね 何通りの実装方法があるか 皆さんご存知ですか?
None
全て同じ出力結果を得られます
ざっと連ねると18通り - 基本構文: for, while, do-while - イテレーション: for...of, for...in
- コレクション: Map(forEach), Set(forEach), Set(for...of) - Array.prototype: forEach, map, reduce - Library: ・jQuery: each ・underscore: each, map, reduce ・lodash: forEach, map, reduce 他Libraryを含めばもっともっとあるはず
この中で1番つえーやつはどいつだ?
天下一武道会を開催することにした
会場: ルール: その他: 純粋な実行スピード 平均実行速度 “要素内の数値を全て計算し合計値を返すまでの処理時間を計測” この処理を反復(100000)してサイズ(10〜100000)ごとに (TOP3の順位)と を求める 配列とコレクションの生成時間は実行時間に含めない
Google Chrome(V8)
https://github.com/camcam-lemon/LoopPerfomanceSimulator デモ用のサンプル yarn install yarn start
for...inは予選落ち 圧倒的に遅いので除外
いざ開幕!
平均実行速度 実行スピード サイズ10 : ループ10
・どの処理もTOP3になる 実行スピード 平均実行速度 明確な差は見られない ・ サイズ10 : ループ10
平均実行速度 実行スピード サイズ10 : ループ100000
どのAPIを使っても良さそう ・Libraryの処理は標準APIに比べて若干遅い ・速度の違いはあれど誤差の範疇(ミリ秒単位の話) 平均実行速度 トップを取った回数に劇的な差は見られない ・ while構文が速い!! ・ (do-while ≧
while > for? ) 実行スピード サイズ10 : ループ100000
平均実行速度 実行スピード サイズ100 : ループ100000
平均実行速度 実行スピード 目立った変化はない サイズ100 : ループ100000
実行スピード 平均実行速度 サイズ1000 : ループ100000
サイズ1000 : ループ100000 平均実行速度 実行スピード jQuery.eachが突然速くなる
サイズが大きくなると各APIの特色が出始める コレクションはfor...ofで回せるSetが頭1つ飛び出た速度を出す ・ jQuery.eachどうした!? ・ reduceとforEachが健闘してる中、mapは失速してきた ・ for...ofは基本構文とほぼ同等の速度を維持 ・ 基本構文がトップを独占
・ 平均実行速度 while強い ・ 90000 => 70000 第とブレが生じ始める ・ 実行スピード サイズ1000 : ループ100000
サイズ10000 : ループ100000 実行スピード 平均実行速度
1000 => 10000 に大きな違いは見られない jQueryは安定した速度を維持 ・ 実行スピードはfor文が速いが平均速度で見ると違いは極わずか ・ 平均実行速度 メンツは変わらず
・ 実行スピード サイズ10000 : ループ100000
サイズ100000 : ループ100000 実行スピード 平均実行速度
jQuery強し ・ 逆にmapはサイズが大きくなるほど弱くなる ・ Array.prototypeはサイズが大きくなるほどreduceが強くなる ・ for...ofと基本構文が速い ・ 平均実行速度 わずかだがfor...ofがwhileを上回る
・ while属強し ・ 実行スピード サイズ100000 : ループ100000
サイズを大きくすればするほど違いが 顕著に表れてくる結果になった
jQuery.eachすげえ(1番予想外だった) ・ Array.prototypeはreduceが頭1つ飛び抜けた強さ ・ コレクションはfor...ofが使えるSetが強い ・ for-ofはサイズが大きくなればなるほど強くなる ・ 基本構文はサイズによらずハイパフォーマンス ・
まとめ
反復処理はその場に適したAPIを使いましょう ハイパフォーマンスな実装 質の良いコード ≠
優勝は・・・
do-while
ご静聴ありがとうございました!