dumping ground for random patches and texts
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: spew@80x24.org
Subject: [PATCH] add benchmark for IO.copy_stream IO#write case
Date: Sat, 31 Dec 2016 00:39:58 +0000	[thread overview]
Message-ID: <20161231003958.10607-1-e@80x24.org> (raw)

I will attempt to reduce garbage in proposed fix
for https://bugs.ruby-lang.org/issues/13085
---
 benchmark/bm_io_copy_stream_write.rb | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
 create mode 100644 benchmark/bm_io_copy_stream_write.rb

diff --git a/benchmark/bm_io_copy_stream_write.rb b/benchmark/bm_io_copy_stream_write.rb
new file mode 100644
index 0000000..3fd8725
--- /dev/null
+++ b/benchmark/bm_io_copy_stream_write.rb
@@ -0,0 +1,24 @@
+# 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)
-- 
EW


                 reply	other threads:[~2016-12-31  0:40 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161231003958.10607-1-e@80x24.org \
    --to=e@80x24.org \
    --cc=spew@80x24.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).