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
900
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
180
Rubyアソシエーション開発助成成果報告会
284km
0
2.1k
Charty - Visualize Real-world Data with Ruby
284km
1
2.4k
Charty - Visualizing your data in Ruby
284km
0
2.3k
.so にして色々な言語から便利にのっかろう
284km
0
68
Pragmatic Charty
284km
0
2.2k
Charty with Rails
284km
1
65
Charty (RubyGrant 2018)
284km
0
2.3k
Better CSV processing with Ruby 2.6
284km
0
89
Other Decks in Programming
See All in Programming
GoのGenericsによるslice操作との付き合い方
syumai
3
680
Cursor AI Agentと伴走する アプリケーションの高速リプレイス
daisuketakeda
1
130
Java on Azure で LangGraph!
kohei3110
0
170
F#で自在につくる静的ブログサイト - 関数型まつり2025
pizzacat83
1
310
Team topologies and the microservice architecture: a synergistic relationship
cer
PRO
0
1k
ReadMoreTextView
fornewid
1
480
AIプログラマーDevinは PHPerの夢を見るか?
shinyasaita
1
110
ASP.NETアプリケーションのモダナイズ インフラ編
tomokusaba
1
410
明示と暗黙 ー PHPとGoの インターフェイスの違いを知る
shimabox
2
300
Julia という言語について (FP in Julia « SIDE: F ») for 関数型まつり2025
antimon2
3
980
Rubyでやりたい駆動開発 / Ruby driven development
chobishiba
1
370
datadog dash 2025 LLM observability for reliability and stability
ivry_presentationmaterials
0
110
Featured
See All Featured
Thoughts on Productivity
jonyablonski
69
4.7k
Fantastic passwords and where to find them - at NoRuKo
philnash
51
3.3k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
48
5.4k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
8
670
Reflections from 52 weeks, 52 projects
jeffersonlam
351
20k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
45
7.4k
We Have a Design System, Now What?
morganepeng
53
7.7k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
252
21k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
50k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
53k
Designing for Performance
lara
609
69k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
48
2.8k
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
ͷ࣮Λ͍ͯΈΔ ೖΓޱͱͯ͠ͷϕϯνϚʔΫྑ͍