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
|
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'async'
require 'async/io'
require 'benchmark/ips'
def measure(pipe, count)
i, o = pipe
count.times do
o.write("Hello World")
i.read(11)
end
end
Benchmark.ips do |benchmark|
benchmark.time = 10
benchmark.warmup = 2
benchmark.report("Async::IO.pipe") do |count|
Async do |task|
measure(::Async::IO.pipe, count)
end
end
benchmark.report("IO.pipe") do |count|
Async do |task|
measure(::IO.pipe, count)
end
end
benchmark.compare!
end
|