Sha256: 39f3127b595856870755846b399ad941d6fd4b4d413ac489212a3637367dd89a

Contents?: true

Size: 938 Bytes

Versions: 4

Compression:

Stored size: 938 Bytes

Contents

require 'benchmark/ips'

RSpec.describe Async::Wrapper do
	let(:pipe) {IO.pipe}
	
	after do
		pipe.each(&:close)
	end
	
	let(:input) {described_class.new(pipe.first)}
	let(:output) {described_class.new(pipe.last)}
	
	it "should be fast to wait until readable" do
		Benchmark.ips do |x|
			x.report('Wrapper#wait_readable') do |repeats|
				Async do |task|
					input = Async::Wrapper.new(pipe.first, task.reactor)
					output = pipe.last
					
					repeats.times do
						output.write(".")
						input.wait_readable
						input.io.read(1)
					end
					
					input.reactor = nil
				end
			end
			
			x.report('Reactor#register') do |repeats|
				Async do |task|
					input = pipe.first
					monitor = task.reactor.register(input, :r)
					output = pipe.last
					
					repeats.times do
						output.write(".")
						Async::Task.yield
						input.read(1)
					end
					
					monitor.close
				end
			end
			
			x.compare!
		end
	end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
async-1.20.1 spec/async/performance_spec.rb
async-1.20.0 spec/async/performance_spec.rb
async-1.19.0 spec/async/performance_spec.rb
async-1.18.0 spec/async/performance_spec.rb