Skip to content

Commit

Permalink
Add simple benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Feb 16, 2018
1 parent cf58afd commit 5ee3f9c
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions benchmark/async_vs_lightio.rb
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

0 comments on commit 5ee3f9c

Please sign in to comment.