From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS49335 158.255.7.0/24 X-Spam-Status: No, score=-0.8 required=3.0 tests=BAYES_00,RCVD_IN_BRBL_LASTEXT, RDNS_NONE,SPF_FAIL,SPF_HELO_FAIL,TO_EQ_FM_DOM_SPF_FAIL shortcircuit=no autolearn=no autolearn_force=no version=3.4.0 Received: from 80x24.org (unknown [158.255.7.61]) by dcvr.yhbt.net (Postfix) with ESMTP id 859EE200E0 for ; Sat, 31 Dec 2016 00:40:04 +0000 (UTC) From: Eric Wong To: spew@80x24.org Subject: [PATCH] add benchmark for IO.copy_stream IO#write case Date: Sat, 31 Dec 2016 00:39:58 +0000 Message-Id: <20161231003958.10607-1-e@80x24.org> List-Id: 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