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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
秒速284km
March 10, 2018
Programming
990
2
Share
Fast Code for Ruby
沖縄Ruby会議02 #okrk02
http://ruby.okinawa/okrk02/
秒速284km
March 10, 2018
More Decks by 秒速284km
See All by 秒速284km
fukuoka_ruby_2019
284km
0
210
Rubyアソシエーション開発助成成果報告会
284km
0
2.4k
Charty - Visualize Real-world Data with Ruby
284km
1
2.7k
Charty - Visualizing your data in Ruby
284km
0
2.5k
.so にして色々な言語から便利にのっかろう
284km
0
100
Pragmatic Charty
284km
0
2.5k
Charty with Rails
284km
1
100
Charty (RubyGrant 2018)
284km
0
2.6k
Better CSV processing with Ruby 2.6
284km
0
120
Other Decks in Programming
See All in Programming
KMP × Kotlin 2.3 - How Android Got Slower While iOS Builds Improved by 47%
rio432
0
130
アクセシビリティ試験の"その後"を仕組み化する
yuuumiravy
1
190
Import assertionsが消えた日~ECMAScriptの仕様はどう決まり、なぜ覆るのか~
bicstone
2
180
なぜあなたのコードには「コシ」がないのか?〜AI時代に問う、最後まで美味しい設計と戦略〜 #phpconkagawa / phpconkagawa2026
shogogg
0
140
検索設計から 推論設計への重心移動と Recall-First Retrieval
po3rin
5
1.5k
Kingdom of the Machine
yui_knk
2
1.4k
AI時代のエンジニアリングの原則 / Engineering Principles in the AI Era
haru860
0
1.1k
Structured Concurrency, Scoped Values and Joiners in the JDK 25 26 27
josepaumard
1
140
Building on Bluesky's AT Protocol with Ruby
mackuba
0
100
Making the RBS Parser Faster
soutaro
0
660
ソースコード→AST→オペコード、の旅を覗いてみる
o0h
PRO
1
130
書籍「ユーザーストーリーマッピング」が私のバイブル
asumikam
4
480
Featured
See All Featured
Ethics towards AI in product and experience design
skipperchong
2
270
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
270
Between Models and Reality
mayunak
3
280
Joys of Absence: A Defence of Solitary Play
codingconduct
1
360
How Software Deployment tools have changed in the past 20 years
geshan
0
33k
Information Architects: The Missing Link in Design Systems
soysaucechin
0
910
A Modern Web Designer's Workflow
chriscoyier
698
190k
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
1
29
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
450
WENDY [Excerpt]
tessaabrams
10
37k
The SEO Collaboration Effect
kristinabergwall1
1
440
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
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
ͷ࣮Λ͍ͯΈΔ ೖΓޱͱͯ͠ͷϕϯνϚʔΫྑ͍