File: pipe.rb

package info (click to toggle)
ruby-async-io 1.34.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 424 kB
  • sloc: ruby: 3,103; makefile: 4
file content (35 lines) | stat: -rwxr-xr-x 528 bytes parent folder | download
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