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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
秒速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
200
Rubyアソシエーション開発助成成果報告会
284km
0
2.3k
Charty - Visualize Real-world Data with Ruby
284km
1
2.6k
Charty - Visualizing your data in Ruby
284km
0
2.5k
.so にして色々な言語から便利にのっかろう
284km
0
95
Pragmatic Charty
284km
0
2.5k
Charty with Rails
284km
1
100
Charty (RubyGrant 2018)
284km
0
2.5k
Better CSV processing with Ruby 2.6
284km
0
120
Other Decks in Programming
See All in Programming
KagglerがMixSeekを触ってみた
morim
0
360
GC言語のWasm化とComponent Modelサポートの実践と課題 - Scalaの場合
tanishiking
0
130
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
1.2k
見せてもらおうか、 OpenSearchの性能とやらを!
shunta27
1
160
Cyrius ーLinux非依存にコンテナをネイティブ実行する専用OSー
n4mlz
0
260
車輪の再発明をしよう!PHP で実装して学ぶ、Web サーバーの仕組みと HTTP の正体
h1r0
2
470
Nuxt Server Components
wattanx
0
220
GoのDB アクセスにおける 「型安全」と「柔軟性」の両立 - Bob という選択肢
tak848
0
290
Feature Toggle は捨てやすく使おう
gennei
0
390
LM Linkで(非力な!)ノートPCでローカルLLM
seosoft
0
290
ファインチューニングせずメインコンペを解く方法
pokutuna
0
220
AI Assistants for YourAngular Solutions @Angular Graz, March 2026
manfredsteyer
PRO
0
130
Featured
See All Featured
Fashionably flexible responsive web design (full day workshop)
malarkey
408
66k
Accessibility Awareness
sabderemane
0
88
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
80
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
1.8k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Context Engineering - Making Every Token Count
addyosmani
9
790
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
230
Imperfection Machines: The Place of Print at Facebook
scottboms
269
14k
How to Ace a Technical Interview
jacobian
281
24k
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
64
54k
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
450
A Tale of Four Properties
chriscoyier
163
24k
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
ͷ࣮Λ͍ͯΈΔ ೖΓޱͱͯ͠ͷϕϯνϚʔΫྑ͍