-
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'async' | ||
require 'lightio' | ||
|
||
require 'benchmark/ips' | ||
|
||
def run_async(count = 10000) | ||
Async::Reactor.run do |task| | ||
tasks = count.times.map do | ||
# LightIO::Beam is a thread-like executor, use it instead Thread | ||
task.async do |subtask| | ||
# do some io operations in beam | ||
subtask.sleep(0.0001) | ||
end | ||
end | ||
|
||
tasks.each(&:wait) | ||
end | ||
end | ||
|
||
def run_lightio(count = 10000) | ||
beams = count.times.map do | ||
# LightIO::Beam is a thread-like executor, use it instead Thread | ||
LightIO::Beam.new do | ||
# do some io operations in beam | ||
LightIO.sleep(0.0001) | ||
end | ||
end | ||
|
||
beams.each(&:join) | ||
end | ||
|
||
Benchmark.ips do |benchmark| | ||
benchmark.report("lightio") do |count| | ||
run_lightio(count) | ||
end | ||
|
||
benchmark.report("async") do |count| | ||
run_async(count) | ||
end | ||
|
||
benchmark.compare! | ||
end |