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
910
Other Decks in Programming
See All in Programming
なぜイベント駆動が必要なのか - CQRS/ESで解く複雑系システムの課題 -
j5ik2o
10
3.7k
Formの複雑さに立ち向かう
bmthd
1
850
時計仕掛けのCompose
mkeeda
1
300
もう僕は OpenAPI を書きたくない
sgash708
5
1.7k
さいきょうのレイヤードアーキテクチャについて考えてみた
yahiru
3
750
データの整合性を保つ非同期処理アーキテクチャパターン / Async Architecture Patterns
mokuo
47
17k
ソフトウェアエンジニアの成長
masuda220
PRO
10
1.1k
Ruby on cygwin 2025-02
fd0
0
150
Open source software: how to live long and go far
gaelvaroquaux
0
630
sappoRo.R #12 初心者セッション
kosugitti
0
250
Introduction to kotlinx.rpc
arawn
0
700
Kubernetes History Inspector(KHI)を触ってみた
bells17
0
230
Featured
See All Featured
Documentation Writing (for coders)
carmenintech
67
4.6k
Typedesign – Prime Four
hannesfritz
40
2.5k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
120k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
53k
Fashionably flexible responsive web design (full day workshop)
malarkey
406
66k
Fantastic passwords and where to find them - at NoRuKo
philnash
51
3k
Site-Speed That Sticks
csswizardry
4
380
Faster Mobile Websites
deanohume
306
31k
Mobile First: as difficult as doing things right
swwweet
223
9.3k
Designing on Purpose - Digital PM Summit 2013
jponch
117
7.1k
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