mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Use lines instead of split
``` % cat ~/bench-split.yml prelude: | s = "foo\nbar\nbaz\n" benchmark: '/(?<=\n)/': | s.split(/(?<=\n)/) '/^/': | s.split(/^/) 'lines': | s.lines Warming up -------------------------------------- /(?<=\n)/ 459.123k i/s - 467.844k times in 1.018994s (2.18μs/i) /^/ 467.922k i/s - 469.744k times in 1.003894s (2.14μs/i) lines 2.343M i/s - 2.424M times in 1.034677s (426.84ns/i) Calculating ------------------------------------- /(?<=\n)/ 422.347k i/s - 1.377M times in 3.261232s (2.37μs/i) /^/ 477.603k i/s - 1.404M times in 2.939186s (2.09μs/i) lines 2.485M i/s - 7.028M times in 2.828757s (402.47ns/i) Comparison: lines: 2484631.6 i/s /^/: 477603.3 i/s - 5.20x slower /(?<=\n)/: 422346.5 i/s - 5.88x slower ```
This commit is contained in:
parent
182072b211
commit
533070bfc6
1 changed files with 9 additions and 9 deletions
|
@ -21,7 +21,7 @@ class Reline::Config::Test < Reline::TestCase
|
|||
end
|
||||
|
||||
def test_read_lines
|
||||
@config.read_lines(<<~LINES.split(/^/))
|
||||
@config.read_lines(<<~LINES.lines)
|
||||
set bell-style on
|
||||
LINES
|
||||
|
||||
|
@ -71,7 +71,7 @@ class Reline::Config::Test < Reline::TestCase
|
|||
set bell-style on
|
||||
PARTIAL_LINES
|
||||
end
|
||||
@config.read_lines(<<~LINES.split(/^/))
|
||||
@config.read_lines(<<~LINES.lines)
|
||||
$include included_partial
|
||||
LINES
|
||||
|
||||
|
@ -79,7 +79,7 @@ class Reline::Config::Test < Reline::TestCase
|
|||
end
|
||||
|
||||
def test_if
|
||||
@config.read_lines(<<~LINES.split(/^/))
|
||||
@config.read_lines(<<~LINES.lines)
|
||||
$if Ruby
|
||||
set bell-style audible
|
||||
$else
|
||||
|
@ -91,7 +91,7 @@ class Reline::Config::Test < Reline::TestCase
|
|||
end
|
||||
|
||||
def test_if_with_false
|
||||
@config.read_lines(<<~LINES.split(/^/))
|
||||
@config.read_lines(<<~LINES.lines)
|
||||
$if Python
|
||||
set bell-style audible
|
||||
$else
|
||||
|
@ -104,7 +104,7 @@ class Reline::Config::Test < Reline::TestCase
|
|||
|
||||
def test_if_with_indent
|
||||
%w[Ruby Reline].each do |cond|
|
||||
@config.read_lines(<<~LINES.split(/^/))
|
||||
@config.read_lines(<<~LINES.lines)
|
||||
set bell-style none
|
||||
$if #{cond}
|
||||
set bell-style audible
|
||||
|
@ -119,7 +119,7 @@ class Reline::Config::Test < Reline::TestCase
|
|||
|
||||
def test_unclosed_if
|
||||
e = assert_raise(Reline::Config::InvalidInputrc) do
|
||||
@config.read_lines(<<~LINES.split(/(?<=\n)/), "INPUTRC")
|
||||
@config.read_lines(<<~LINES.lines, "INPUTRC")
|
||||
$if Ruby
|
||||
LINES
|
||||
end
|
||||
|
@ -128,7 +128,7 @@ class Reline::Config::Test < Reline::TestCase
|
|||
|
||||
def test_unmatched_else
|
||||
e = assert_raise(Reline::Config::InvalidInputrc) do
|
||||
@config.read_lines(<<~LINES.split(/(?<=\n)/), "INPUTRC")
|
||||
@config.read_lines(<<~LINES.lines, "INPUTRC")
|
||||
$else
|
||||
LINES
|
||||
end
|
||||
|
@ -137,7 +137,7 @@ class Reline::Config::Test < Reline::TestCase
|
|||
|
||||
def test_unmatched_endif
|
||||
e = assert_raise(Reline::Config::InvalidInputrc) do
|
||||
@config.read_lines(<<~LINES.split(/(?<=\n)/), "INPUTRC")
|
||||
@config.read_lines(<<~LINES.lines, "INPUTRC")
|
||||
$endif
|
||||
LINES
|
||||
end
|
||||
|
@ -146,7 +146,7 @@ class Reline::Config::Test < Reline::TestCase
|
|||
|
||||
def test_default_key_bindings
|
||||
@config.add_default_key_binding('abcd'.bytes, 'EFGH'.bytes)
|
||||
@config.read_lines(<<~'LINES'.split(/^/))
|
||||
@config.read_lines(<<~'LINES'.lines)
|
||||
"abcd": "ABCD"
|
||||
"ijkl": "IJKL"
|
||||
LINES
|
||||
|
|
Loading…
Reference in a new issue