Sha256: a22982f770ba0e0d33e6efd2a79f5268e1e7155882396e4249acc2fa7b574564

Contents?: true

Size: 927 Bytes

Versions: 10

Compression:

Stored size: 927 Bytes

Contents

require 'benchmark/ips'

RSpec.describe Async::Wrapper do
	let(:pipe) {IO.pipe}
	
	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::Reactor.run 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::Reactor.run 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

10 entries across 10 versions & 1 rubygems

Version Path
async-1.12.0 spec/async/performance_spec.rb
async-1.11.0 spec/async/performance_spec.rb
async-1.10.3 spec/async/performance_spec.rb
async-1.10.2 spec/async/performance_spec.rb
async-1.10.1 spec/async/performance_spec.rb
async-1.10.0 spec/async/performance_spec.rb
async-1.9.1 spec/async/performance_spec.rb
async-1.9.0 spec/async/performance_spec.rb
async-1.8.0 spec/async/performance_spec.rb
async-1.7.0 spec/async/performance_spec.rb