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
83
スクラムマスターは何をすべきか
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
Jakarta EE meets AI
ivargrimstad
0
570
SwiftUI Viewの責務分離
elmetal
PRO
2
280
Djangoにおける複数ユーザー種別認証の設計アプローチ@DjangoCongress JP 2025
delhi09
PRO
4
500
From the Wild into the Clouds - Laravel Meetup Talk
neverything
0
170
お前もAI鬼にならないか?👹Bolt & Cursor & Supabase & Vercelで人間をやめるぞ、ジョジョー!👺
taishiyade
7
4.2k
GoとPHPのインターフェイスの違い
shimabox
2
210
LINE messaging APIを使ってGoogleカレンダーと連携した予約ツールを作ってみた
takumakoike
0
130
1年目の私に伝えたい!テストコードを怖がらなくなるためのヒント/Tips for not being afraid of test code
push_gawa
1
640
Ça bouge du côté des animations CSS !
goetter
2
160
Rails 1.0 のコードで学ぶ find_by* と method_missing の仕組み / Learn how find_by_* and method_missing work in Rails 1.0 code
maimux2x
1
260
sappoRo.R #12 初心者セッション
kosugitti
0
280
5分で理解する SOLID 原則 #phpcon_nagoya
shogogg
1
400
Featured
See All Featured
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
53k
Building Adaptive Systems
keathley
40
2.4k
Fontdeck: Realign not Redesign
paulrobertlloyd
83
5.4k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
45
9.4k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
6
580
The Cult of Friendly URLs
andyhume
78
6.2k
Statistics for Hackers
jakevdp
797
220k
A Modern Web Designer's Workflow
chriscoyier
693
190k
How GitHub (no longer) Works
holman
314
140k
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
Building a Scalable Design System with Sketch
lauravandoore
461
33k
For a Future-Friendly Web
brad_frost
176
9.6k
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