Sha256: a08208befd5ba694ef6383a25c6410f13eb5390190ae58ac1ab773309f6c3cac

Contents?: true

Size: 898 Bytes

Versions: 2

Compression:

Stored size: 898 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 parse large documents" 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
				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

2 entries across 2 versions & 1 rubygems

Version Path
async-1.4.0 spec/async/performance_spec.rb
async-1.3.0 spec/async/performance_spec.rb