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
Fast Code for Ruby
Search
秒速284km
March 10, 2018
Programming
2
850
Fast Code for Ruby
沖縄Ruby会議02 #okrk02
http://ruby.okinawa/okrk02/
秒速284km
March 10, 2018
Tweet
Share
More Decks by 秒速284km
See All by 秒速284km
fukuoka_ruby_2019
284km
0
140
Rubyアソシエーション開発助成成果報告会
284km
0
2k
Charty - Visualize Real-world Data with Ruby
284km
1
2.3k
Charty - Visualizing your data in Ruby
284km
0
2.2k
.so にして色々な言語から便利にのっかろう
284km
0
48
Pragmatic Charty
284km
0
2.2k
Charty with Rails
284km
1
43
Charty (RubyGrant 2018)
284km
0
2.1k
Better CSV processing with Ruby 2.6
284km
0
67
Other Decks in Programming
See All in Programming
ATDDで素早く安定した デリバリを実現しよう!
tonnsama
1
1.1k
MCP with Cloudflare Workers
yusukebe
2
270
生成AIでGitHubソースコード取得して仕様書を作成
shukob
0
600
Fibonacci Function Gallery - Part 2
philipschwarz
PRO
0
200
Flatt Security XSS Challenge 解答・解説
flatt_security
0
590
return文におけるstd::moveについて
onihusube
1
1.4k
なまけものオバケたち -PHP 8.4 に入った新機能の紹介-
tanakahisateru
1
140
PHPとAPI Platformで作る本格的なWeb APIアプリケーション(入門編) / phpcon 2024 Intro to API Platform
ttskch
0
360
PSR-15 はあなたのための ものではない? - phpcon2024
myamagishi
0
360
AppRouterを用いた大規模サービス開発におけるディレクトリ構成の変遷と問題点
eiganken
1
400
range over funcの使い道と非同期N+1リゾルバーの夢 / about a range over func
mackee
0
200
LLM Supervised Fine-tuningの理論と実践
datanalyticslabo
8
1.8k
Featured
See All Featured
Designing on Purpose - Digital PM Summit 2013
jponch
116
7k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
27
1.5k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
6
490
Embracing the Ebb and Flow
colly
84
4.5k
The Language of Interfaces
destraynor
155
24k
jQuery: Nuts, Bolts and Bling
dougneiner
62
7.6k
Making the Leap to Tech Lead
cromwellryan
133
9k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
29
940
Rebuilding a faster, lazier Slack
samanthasiow
79
8.8k
Documentation Writing (for coders)
carmenintech
67
4.5k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.3k
Agile that works and the tools we love
rasmusluckow
328
21k
Transcript
Fast Code for Ruby @284km
͍͍͞ʂ
ࠓ͢͜ͱ Ruby Ͱ͍ίʔυΛॻ͘ benchmark_driver ͕͘͢͝ྑ͍ Ruby ͷָ͠ΈํΛͻͱͭ
͍ίʔυΛॻ͘
͍ίʔυΛॻ͘ ଌఆ ϕϯνϚʔΧʔ
ϕϯνϚʔΧʔ benchmark.rb (ඪ४ఴϥΠϒϥϦ) evanphx/benchmark-ips k0kubun/benchmark_driver
͍ίʔυ ಉ݁͡Ռ͕ಘΒΕΔෳͷॻ͖ํ ܭଌͯ͠ɺ͍΄͏͕͍ લఏ: ࠓճͷϕϯνϚʔΫͷ MBP Ͱ࣮ߦͨ͠ͷͰ͢
benchmark_driver e.g. ෳͷॲཧܥ ग़ྗܗࣜ (.md Մ)
Hash#keys.each Hash#each_key
Hash#keys.each Hash#each_key
͍ίʔυ ݅ʹґଘ͢Δ߹͕͋Δ ඞͣͦͷॻ͖ํ͕ྑ͍ͱݴ͑ͳ͍ έʔε͕͋Δ (e.g. gsub / tr)
gsub tr
gsub tr
gsub tr
gsub tr
gsub tr
gsub tr
͍ίʔυ Ͳ͏͍͏࣌ʹ༗ޮ͔ΛΔͱΑ͞ ͦ͏ ࣮Λ͘ͱ͔Δ͜ͱ͕͋Δ
Bang method ഁյత / ඇഁյత ͳϝιουͷྫ ͜ͷ࣮ݟ͍͢ͱࢥ͍·͢
Hash#merge Hash#merge! ͜͜Ͱαϯϓϧίʔυͦ Ε΄ͲॏཁͰͳ͘ɺ
Hash#merge Hash#merge! ͜͜Ͱαϯϓϧίʔυͦ Ε΄ͲॏཁͰͳ͘ɺ ࠩͷཧ༝ΛͬͯΈΔ
Hash#merge Hash#merge! dup ͨ͠ͷΛͯ݁͠ ՌΛฦ͍ͯ͠ΔͷͰͦͷ ͍
͞ ͱɺಡΈ͢͞
each_with_index while
each_with_index while
ಡΈ͢͞େࣄ ಡΈ͢͞ͱ…(ޙͰʹ͠·͢ ͕ yield / Proc#call ͦ͏Ͱ͢ΑͶ) ࣄͰॻ͘ίʔυͰɺνʔϜͷࣄ ͳͲʹΑͬͯԿ͕ಡΈ͍͔͢ม ΘΓͦ͏Ͱ͋Δʢͷײ
Rubocop::Cop::Performance ύϑΥʔϚϯε͕վળ͞Εͦ͏ͳͱ ͜ΖΛࢦఠͯ͘͠ΕΔ ੩తղੳπʔϧʹཔΔ͜ͱ༗ޮ ͜ͷؒͻͱͭࢦఠ͞Ε·ͨ͠
String#match String#match?
String#match String#match?
String#match String#match?
String#match String#match? MatchData ΦϒδΣΫτ Λฦ͢ʢϚονͨ͠߹ʣ
String#match String#match? MatchData ΦϒδΣΫτ Λฦ͢ʢϚονͨ͠߹ʣ rb_reg_match_p() ɺ Ϛονͨ͠Β true ͠ͳ͚
Ε false Λฦ͢ɻ
Ruby 2.5 ͍ͬͯ·͔͢ʁ όʔδϣϯΞοϓͱڞʹվળ͞ΕΔ ෦͓ͬͯ͘ͱศར
unpack1 unpack.first String#unpack1 2.4 Ͱೖ ͬͨ
unpack1 unpack.first String#unpack1 2.4 Ͱೖ ͬͨ
yield Proc#call 2.5 Ͱ Proc#call ͕͘ ͳͬͨ
yield Proc#call
yield Proc#call
࠷৽ͷ Ruby ͬͯΔͱࣄָ͕ʹͳͬͨΓ͢Δ Δͱɺ͏ͷָ͕͘͠ͳΔϧʔϓ JIT Λ༗ޮʹ͢Δͱɺ݁ՌͷมΘΔ ϕϯνϚʔΫ͋Γͦ͏ (2.6.0)
·ͱΊ ʹ;͐ʔͰʔͼΔ benchmark_driver ͕͘͢͝ྑ͍ Fast Code ͱ͍͏ Ruby ͷָ͠Έํ Ruby
ͷ࣮Λ͍ͯΈΔ ೖΓޱͱͯ͠ͷϕϯνϚʔΫྑ͍