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

ruby-changes:45165

From: normal <ko1@a...>
Date: Sat, 31 Dec 2016 09:41:23 +0900 (JST)
Subject: [ruby-changes:45165] normal:r57237 (trunk): add benchmark for IO.copy_stream IO#write case

normal	2016-12-31 09:41:14 +0900 (Sat, 31 Dec 2016)

  New Revision: 57237

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57237

  Log:
    add benchmark for IO.copy_stream IO#write case
    
    I will attempt to reduce garbage in proposed fix
    for https://bugs.ruby-lang.org/issues/13085

  Added files:
    trunk/benchmark/bm_io_copy_stream_write.rb
Index: benchmark/bm_io_copy_stream_write.rb
===================================================================
--- benchmark/bm_io_copy_stream_write.rb	(revision 0)
+++ benchmark/bm_io_copy_stream_write.rb	(revision 57237)
@@ -0,0 +1,24 @@ https://github.com/ruby/ruby/blob/trunk/benchmark/bm_io_copy_stream_write.rb#L1
+# The goal of this is to use a synthetic (non-IO) reader
+# to trigger the read/write loop of IO.copy_stream,
+# bypassing in-kernel mechanisms like sendfile for zero copy,
+# so we wrap the /dev/zero IO object:
+
+class Zero
+  def initialize
+    @n = 100000
+    @in = File.open('/dev/zero', 'rb')
+  end
+
+  def read(len, buf)
+    return if (@n -= 1) == 0
+    @in.read(len, buf)
+  end
+end
+
+begin
+  src = Zero.new
+  dst = File.open(IO::NULL, 'wb')
+  n = IO.copy_stream(src, dst)
+rescue Errno::ENOENT
+  # not *nix
+end if IO.respond_to?(:copy_stream) && IO.const_defined?(:NULL)

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

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