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
160
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
86
スクラムマスターは何をすべきか
irohiroki
1
610
高階関数みたいな鳥たちの森
irohiroki
0
120
Pattern Language for Rubyists (Rev.2)
irohiroki
1
330
The Most Beautiful Vagrant Box
irohiroki
1
220
ドメイン駆動設計ワークショップ in KRAY
irohiroki
1
300
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
Denoでフロントエンド開発 2025年春版 / Frontend Development with Deno (Spring 2025)
petamoriken
1
1.2k
Scala 3 で GLSL のための c-like-for を実装してみた
exoego
1
160
小さく段階的リリースすることで深夜メンテを回避する
mkmk884
2
110
Go1.24 go vetとtestsアナライザ
kuro_kurorrr
2
330
remix + cloudflare workers (DO) docker上でいい感じに開発する
yoshidatomoaki
0
110
CTFのWebにおける⾼難易度問題について
hamayanhamayan
1
890
RailsでCQRS/ESをやってみたきづき
suzukimar
2
1.4k
RubyKaigiで手に入れた HHKB Studioのための HIDRawドライバ
iberianpig
0
130
マルチアカウント環境での、そこまでがんばらない RI/SP 運用設計
wa6sn
0
150
Node.js, Deno, Bun 最新動向とその所感について
yosuke_furukawa
PRO
6
2.9k
Firebase Dynamic Linksの代替手段を自作する / Create your own Firebase Dynamic Links alternative
kubode
0
140
OpenTelemetryを活用したObservability入門 / Introduction to Observability with OpenTelemetry
seike460
PRO
0
190
Featured
See All Featured
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.7k
Making the Leap to Tech Lead
cromwellryan
133
9.2k
Adopting Sorbet at Scale
ufuk
75
9.3k
Making Projects Easy
brettharned
116
6.1k
Mobile First: as difficult as doing things right
swwweet
223
9.5k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
28
2k
How to train your dragon (web standard)
notwaldorf
91
5.9k
How to Think Like a Performance Engineer
csswizardry
22
1.4k
Side Projects
sachag
452
42k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.3k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
233
17k
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