Skip to content

Instantly share code, notes, and snippets.

@razielgn
Last active December 18, 2015 17:29
Show Gist options
  • Save razielgn/5818831 to your computer and use it in GitHub Desktop.
Save razielgn/5818831 to your computer and use it in GitHub Desktop.
Major slowdown in String#gsub and String#gsub! (UTF-8 input with ASCII replacement) after commit f4fd34a.
Benchmark.ips do |x|
str1 = "YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFh\n" * 6000
repl1 = "\r\n"
x.report 'gsub ASCII with ASCII' do
str1.gsub(/\n|\r\n|\r/){ repl1 }
end
str2 = "YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFh\n" * 6000
str2.encode! 'utf-8'
repl2 = "\r\n"
x.report 'gsub UTF-8 with ASCII' do
str2.gsub(/\n|\r\n|\r/){ repl2 }
end
str3 = "YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFh\n" * 6000
str3.encode! 'utf-8'
repl3 = "\r\n"
repl3.encode! 'utf-8'
x.report 'gsub UTF-8 with UTF-8' do
str3.gsub(/\n|\r\n|\r/){ repl3 }
end
end
rubinius 2.0.0.rc1 (1.9.3 215cc7ac yyyy-mm-dd JI) [x86_64-unknown-linux-gnu]
=== /usr/local/rubinius/2.0/bin/rbx ===
gsub ASCII with ASCII
79.8 (±12.5%) i/s - 390 in 5.001304s (cycle=5)
gsub UTF-8 with ASCII
1.1 (±0.0%) i/s - 6 in 5.347251s (cycle=1)
gsub UTF-8 with UTF-8
54.4 (±5.5%) i/s - 272 in 5.021096s (cycle=4)
rubinius 2.0.0rc1 (1.9.3 b89c065b 2012-11-02 JI) [x86_64-unknown-linux-gnu]
=== bin/rbx ===
gsub ASCII with ASCII
55.1 (±14.5%) i/s - 275 in 5.102085s (cycle=5)
gsub UTF-8 with ASCII
40.3 (±14.9%) i/s - 198 in 5.011385s (cycle=3)
gsub UTF-8 with UTF-8
40.0 (±12.5%) i/s - 198 in 5.030680s (cycle=3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment