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
RubyとPythonはどちらが速いのか
Search
Hiroki Yoshioka
June 29, 2019
Programming
0
150
RubyとPythonはどちらが速いのか
Lightening talk at #tqrk13
Hiroki Yoshioka
June 29, 2019
Tweet
Share
More Decks by Hiroki Yoshioka
See All by Hiroki Yoshioka
ペアプロってどうなの?
irohiroki
0
82
スクラムマスターは何をすべきか
irohiroki
1
600
高階関数みたいな鳥たちの森
irohiroki
0
120
Pattern Language for Rubyists (Rev.2)
irohiroki
1
330
The Most Beautiful Vagrant Box
irohiroki
1
220
ドメイン駆動設計ワークショップ in KRAY
irohiroki
1
290
Gitはなぜ難しいのか
irohiroki
4
25k
Github APIを叩いて分かったこと
irohiroki
1
680
The Metric Talks or Not
irohiroki
2
920
Other Decks in Programming
See All in Programming
AIの力でお手軽Chrome拡張機能作り
taiseiue
0
190
「個人開発マネタイズ大全」が教えてくれたこと
bani24884
1
200
ソフトウェアエンジニアの成長
masuda220
PRO
12
2.1k
pylint custom ruleで始めるレビュー自動化
shogoujiie
0
150
Serverless Rust: Your Low-Risk Entry Point to Rust in Production (and the benefits are huge)
lmammino
1
150
CI改善もDatadogとともに
taumu
0
200
Datadog DBMでなにができる? JDDUG Meetup#7
nealle
0
150
PHPのバージョンアップ時にも役立ったAST
matsuo_atsushi
0
230
機能が複雑化しても 頼りになる FactoryBotの話
tamikof
0
160
ファインディLT_ポケモン対戦の定量的分析
fufufukakaka
0
920
ナレッジイネイブリングにAIを活用してみる ゆるSRE勉強会 #9
nealle
0
160
CloudNativePGを布教したい
nnaka2992
0
110
Featured
See All Featured
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
175
52k
Measuring & Analyzing Core Web Vitals
bluesmoon
6
260
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.3k
GitHub's CSS Performance
jonrohan
1030
460k
Making the Leap to Tech Lead
cromwellryan
133
9.1k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.3k
VelocityConf: Rendering Performance Case Studies
addyosmani
328
24k
Fontdeck: Realign not Redesign
paulrobertlloyd
83
5.4k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
49k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
27
1.9k
Testing 201, or: Great Expectations
jmmastey
42
7.2k
Building Flexible Design Systems
yeseniaperezcruz
328
38k
Transcript
Copyright Drecom Co., Ltd. All Rights Reserved. !1 3VCZͱ1ZUIPO ͲͪΒ͕͍ͷ͔ʁ
URSL ٢ԬͻΖ͖
Copyright Drecom Co., Ltd. All Rights Reserved. !2 自己紹介 吉岡ひろき
Webエンジニア irohiroki / いろ 登壇、執筆 少々
Copyright Drecom Co., Ltd. All Rights Reserved. !3 今どきのゲーム 何でも自動
ʰࠇ͍࠭യʱͷࣗಈङΓ
Copyright Drecom Co., Ltd. All Rights Reserved. !4 今どきのゲーム 何でも自動
自動戦闘 自動移動 自動アイテム処分 自動装備 自動パーティ編成 …
Copyright Drecom Co., Ltd. All Rights Reserved. !5 今どきのゲーム 何でも自動
自動戦闘 自動移動 自動アイテム処分 自動装備 自動パーティ編成 … 組合せ最適化問題 ʢ͍ΘΏΔφοϓαοΫʣ
Copyright Drecom Co., Ltd. All Rights Reserved. !6 組合せ最適化問題 近似解法
ミツバチコロニー最適化など 厳密解法 動的計画法 バックトラッキング 分岐限界法 など
Copyright Drecom Co., Ltd. All Rights Reserved. !7 あるブログ
Copyright Drecom Co., Ltd. All Rights Reserved. !8 ίʔυ3VCZ൛ͱಉ͚ͩ͡Ͳ ʢ1ZUIPOͷํ͕ʣ͍Έ͍ͨɻ
ͳ͔ͥΒͳ͍͚Ͳʂ
Copyright Drecom Co., Ltd. All Rights Reserved. !9 喧嘩売ってる?
Copyright Drecom Co., Ltd. All Rights Reserved. !10 検証 安定版
Ruby 2.6.3 Python 3.7.3 分岐限界法
Copyright Drecom Co., Ltd. All Rights Reserved. !11 分岐限界法 #
Value Cost V/C 1 14 4 3.5 2 18 6 3 3 5 2 2.5 4 3 2 1.5 Cap=6
Copyright Drecom Co., Ltd. All Rights Reserved. !12 分岐限界法 V:0,
C:0 UB:20 # Value Cost V/C 1 14 4 3.5 2 18 6 3 3 5 2 2.5 4 3 2 1.5 Cap=6 UB = 14 + 18 * (6 - 4) / 6
Copyright Drecom Co., Ltd. All Rights Reserved. !13 分岐限界法 V:0,
C:0 UB:20 V:14, C:4 UB: 20 # Value Cost V/C 1 14 4 3.5 2 18 6 3 3 5 2 2.5 4 3 2 1.5 Cap=6 + I1 UB = 14 + 18 * (6 - 4) / 6
Copyright Drecom Co., Ltd. All Rights Reserved. !14 分岐限界法 V:0,
C:0 UB:20 V:14, C:4 UB: 20 V: , C:10 UB: # Value Cost V/C 1 14 4 3.5 2 18 6 3 3 5 2 2.5 4 3 2 1.5 Cap=6 + I1 + I2
Copyright Drecom Co., Ltd. All Rights Reserved. !15 分岐限界法 V:0,
C:0 UB:20 V:14, C:4 UB: 20 V: , C:10 UB: V:14, C:4 UB:19 # Value Cost V/C 1 14 4 3.5 2 18 6 3 3 5 2 2.5 4 3 2 1.5 Cap=6 + I1 + I2 - I2 UB = 14 + 5 * (6 - 4) / 2
Copyright Drecom Co., Ltd. All Rights Reserved. !16 分岐限界法 V:0,
C:0 UB:20 V:14, C:4 UB: 20 V:0, C:0 UB: 18 V: , C:10 UB: V:14, C:4 UB:19 # Value Cost V/C 1 14 4 3.5 2 18 6 3 3 5 2 2.5 4 3 2 1.5 Cap=6 + I1 - I1 + I2 - I2
Copyright Drecom Co., Ltd. All Rights Reserved. !17 分岐限界法 V:0,
C:0 UB:20 V:14, C:4 UB: 20 V:0, C:0 UB: 18 V: , C:10 UB: V:14, C:4 UB:19 # Value Cost V/C 1 14 4 3.5 2 18 6 3 3 5 2 2.5 4 3 2 1.5 Cap=6 V:19, C:6 UB:19 + I1 - I1 + I2 - I2 + I3
Copyright Drecom Co., Ltd. All Rights Reserved. !18 分岐限界法 V:0,
C:0 UB:20 V:14, C:4 UB: 20 V:0, C:0 UB: 18 V: , C:10 UB: V:14, C:4 UB:19 # Value Cost V/C 1 14 4 3.5 2 18 6 3 3 5 2 2.5 4 3 2 1.5 Cap=6 V:19, C:6 UB:19 V:14, C:4 UB:17 + I1 - I1 + I2 - I2 + I3 - I3
Copyright Drecom Co., Ltd. All Rights Reserved. !19 分岐限界法 V:0,
C:0 UB:20 V:14, C:4 UB: 20 V:0, C:0 UB: 18 V: , C:10 UB: V:14, C:4 UB:19 # Value Cost V/C 1 14 4 3.5 2 18 6 3 3 5 2 2.5 4 3 2 1.5 Cap=6 V:19, C:6 UB:19 V:14, C:4 UB:17 + I1 - I1 + I2 - I2 + I3 - I3
Copyright Drecom Co., Ltd. All Rights Reserved. !20 irohiroki/knapsacker
Copyright Drecom Co., Ltd. All Rights Reserved. !21 irohiroki/knapsacker-py
Copyright Drecom Co., Ltd. All Rights Reserved. !22 テストデータ アイテム数
… 200 Value … 1 〜 10 Cost … 1 〜 10 キャパシティ … 500
Copyright Drecom Co., Ltd. All Rights Reserved. !23 0.42秒 Rubyで解く
Copyright Drecom Co., Ltd. All Rights Reserved. !24 118 /
200 3.5 x 1057 通り Rubyで解く
Copyright Drecom Co., Ltd. All Rights Reserved. !25 Pythonで解く
Copyright Drecom Co., Ltd. All Rights Reserved. !26 0.14秒 Pythonで解く
Copyright Drecom Co., Ltd. All Rights Reserved. !27 Pythonで解く 0.14秒
Pythonの方が速い
Copyright Drecom Co., Ltd. All Rights Reserved. !28 Pythonで解く 3倍速い
0.42秒 0.14秒
Copyright Drecom Co., Ltd. All Rights Reserved. !29 ちょっと待って
Copyright Drecom Co., Ltd. All Rights Reserved. !30 リハーサルの方が速い…? Rubyで解く
2
Copyright Drecom Co., Ltd. All Rights Reserved. !31 リハーサルやめる benchmark.bmbm
benchmark.bm
Copyright Drecom Co., Ltd. All Rights Reserved. !32 リハーサルなし 0.18秒
Copyright Drecom Co., Ltd. All Rights Reserved. !33 他のデータで…
Copyright Drecom Co., Ltd. All Rights Reserved. アイテム数 … 200
Value … 1 〜 10 Cost … 1 〜 10 キャパシティ … 503 !34 テストデータ2 +3
Copyright Drecom Co., Ltd. All Rights Reserved. !35 0.02秒 Rubyで解く
2 ʢࢀߟɿͷͱ͖ඵʣ
Copyright Drecom Co., Ltd. All Rights Reserved. !36 0.03秒 Pythonで解く
2
Copyright Drecom Co., Ltd. All Rights Reserved. !37 0.03秒 Pythonで解く
2 勝った
Copyright Drecom Co., Ltd. All Rights Reserved. !38 キャパシティ 500〜599
Copyright Drecom Co., Ltd. All Rights Reserved. !39 JITがある!
Copyright Drecom Co., Ltd. All Rights Reserved. !40 JITとは 一部をCに変換、コンパイルして実行
→ 速くなる 2.6から実験的に組み込まれている
Copyright Drecom Co., Ltd. All Rights Reserved. !41 --jit
Copyright Drecom Co., Ltd. All Rights Reserved. !42 キャパシティ 500〜599
Copyright Drecom Co., Ltd. All Rights Reserved. !43 結論 Pythonの方が速かった
Copyright Drecom Co., Ltd. All Rights Reserved. !44 Python vs
Ruby https://www.educba.com/python-vs-ruby-performance/
Copyright Drecom Co., Ltd. All Rights Reserved. !45 https://www.educba.com/python-vs-ruby-performance/ Python
vs Ruby એݴత ಈత
Copyright Drecom Co., Ltd. All Rights Reserved. !46 https://www.educba.com/python-vs-ruby-performance/ Python
vs Ruby ؆ܿͰ ϚδΧϧ తͰ ಡΈ͍͢
Copyright Drecom Co., Ltd. All Rights Reserved. !47 https://www.educba.com/python-vs-ruby-performance/ Python
vs Ruby ؆͕ܿͩ σόοά͠ʹ͍͘͜ͱ ໌ࣔత͕ͩ ΤϨΨϯτͰͳ͍͜ͱ
Copyright Drecom Co., Ltd. All Rights Reserved. !48 https://www.educba.com/python-vs-ruby-performance/ Python
vs Ruby ΣϒΞϓϦͷ ϓϩτλΠϐϯά େྔͷσʔλͱܭࢉ
Copyright Drecom Co., Ltd. All Rights Reserved. !49 速さで選んでるんじゃないし。
Copyright Drecom Co., Ltd. All Rights Reserved. !50 おまけ -
Python書いたら self忘れる return忘れる メソッド呼ぶとき()忘れる メソッドじゃないのに()つけちゃう true → True y if x else z
Copyright Drecom Co., Ltd. All Rights Reserved. !51 Rubyの方がいいし。 End