File: bm_common.rb

package info (click to toggle)
ruby-httpclient 2.8.3%2Bgit20211122.4658227-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,908 kB
  • sloc: ruby: 9,963; makefile: 10; sh: 2
file content (49 lines) | stat: -rw-r--r-- 1,184 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
require 'benchmark'
require 'uri'
require 'fileutils'

def try_require(target)
  begin
    require target
  rescue LoadError
    warn("#{target} not loaded")
  end
end

try_require 'httpclient'
require 'net/http'

# following Net code block is not copirighed by me.
# see: http://7fff.com/2008/12/20/faster-nethttp-for-ruby-186
module Net
  class BufferedIO
    alias rbuf_fill_replaced_by_bm rbuf_fill
    BUFSIZE = 1024 * 16  
    def rbuf_fill  
      # HTTPS can't use the non-blocking strategy below in 1.8.6; so at least  
      # increase buffer size over 1.8.6 default of 1024  
      if !@io.respond_to? :read_nonblock  
        timeout(@read_timeout) {  
          @rbuf << @io.sysread(BUFSIZE)  
        }  
        return  
      end  
      # non-blocking  
      begin  
        @rbuf << @io.read_nonblock(BUFSIZE)  
      rescue Errno::EWOULDBLOCK  
        if IO.select([@io], nil, nil, @read_timeout)  
          @rbuf << @io.read_nonblock(BUFSIZE)  
        else  
          raise Timeout::TimeoutError  
        end  
      end  
    end
  end
end

require 'open-uri'
try_require 'rfuzz/session'
try_require 'eventmachine'
try_require 'curb'
try_require 'httparty'