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
80
スクラムマスターは何をすべきか
irohiroki
1
590
高階関数みたいな鳥たちの森
irohiroki
0
110
Pattern Language for Rubyists (Rev.2)
irohiroki
1
310
The Most Beautiful Vagrant Box
irohiroki
1
210
ドメイン駆動設計ワークショップ in KRAY
irohiroki
1
290
Gitはなぜ難しいのか
irohiroki
4
25k
Github APIを叩いて分かったこと
irohiroki
1
680
The Metric Talks or Not
irohiroki
2
840
Other Decks in Programming
See All in Programming
サーバーレスで負荷試験!Step Functions + Lambdaを使ったk6の分散実行
shuntakahashi
6
1.6k
Rechartsで楽にゴリゴリにカスタマイズする!
10tera
1
170
What is Parser
yui_knk
9
4.2k
Modernisation Progressive d’Applications PHP
hhamon
0
110
いつか使える ObjectSpace / Maybe useful ObjectSpace
euglena1215
2
140
Some more adventure of Happy Eyeballs
coe401_
2
190
LangChainの現在とv0.3にむけて
os1ma
4
940
XStateでReactに秩序を与えたい
gizm000
0
740
Increased Performance and Developer Productivity with Jakarta EE 11
ivargrimstad
0
410
Scala におけるコンパイラエラーとの付き合い方
chencmd
2
430
Method Swizzlingを行うライブラリにおけるマルチモジュール設計
yoshikma
0
120
Regular Expressions, REXML, Automata Learning
makenowjust
0
220
Featured
See All Featured
Infographics Made Easy
chrislema
239
18k
A Modern Web Designer's Workflow
chriscoyier
692
190k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
89
16k
Building Your Own Lightsaber
phodgson
101
6k
Writing Fast Ruby
sferik
623
60k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
8.9k
Pencils Down: Stop Designing & Start Developing
hursman
119
11k
Building Adaptive Systems
keathley
36
2.1k
Facilitating Awesome Meetings
lara
49
6k
We Have a Design System, Now What?
morganepeng
48
7.1k
A Philosophy of Restraint
colly
202
16k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
326
21k
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