[前][次][番号順一覧][スレッド一覧]

ruby-changes:56090

From: Kazuhiro <ko1@a...>
Date: Wed, 12 Jun 2019 10:33:13 +0900 (JST)
Subject: [ruby-changes:56090] Kazuhiro NISHIYAMA: 533070bfc6 (trunk): Use lines instead of split

https://git.ruby-lang.org/ruby.git/commit/?id=533070bfc6

From 533070bfc69cae5b09103a229e4db33b6af695cb Mon Sep 17 00:00:00 2001
From: Kazuhiro NISHIYAMA <zn@m...>
Date: Mon, 3 Jun 2019 10:32:32 +0900
Subject: Use lines instead of split
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

```
% 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
```

diff --git a/test/reline/test_config.rb b/test/reline/test_config.rb
index c00c4f8..1de8eca 100644
--- a/test/reline/test_config.rb
+++ b/test/reline/test_config.rb
@@ -21,7 +21,7 @@ class Reline::Config::Test < Reline::TestCase https://github.com/ruby/ruby/blob/trunk/test/reline/test_config.rb#L21
   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 https://github.com/ruby/ruby/blob/trunk/test/reline/test_config.rb#L71
         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 https://github.com/ruby/ruby/blob/trunk/test/reline/test_config.rb#L79
   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 https://github.com/ruby/ruby/blob/trunk/test/reline/test_config.rb#L91
   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 https://github.com/ruby/ruby/blob/trunk/test/reline/test_config.rb#L104
 
   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 https://github.com/ruby/ruby/blob/trunk/test/reline/test_config.rb#L119
 
   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 https://github.com/ruby/ruby/blob/trunk/test/reline/test_config.rb#L128
 
   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 https://github.com/ruby/ruby/blob/trunk/test/reline/test_config.rb#L137
 
   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 https://github.com/ruby/ruby/blob/trunk/test/reline/test_config.rb#L146
 
   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
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]