Navigation Menu

Skip to content

Commit

Permalink
Add benchmark script for Coolio::TimerWatcher.
Browse files Browse the repository at this point in the history
Benchmark result:
1.0836857050000002 seconds for 100000 timers
on a development PC (real world)

It is confirmed that overheads for each timer are very small.
This is a good reason to introduce timeout feature based on TimerWatcher
for every messages.
  • Loading branch information
piroor committed Apr 7, 2015
1 parent 43bf6f2 commit bad290c
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions benchmark/timer-watcher/benchmark.rb
@@ -0,0 +1,44 @@
require "coolio"

$times = 100000

def add_timeout_timer(loop)
timeout_timer = Coolio::TimerWatcher.new(60)
timeout_timer.on_timer do
timeout_timer.detach
timeout_timer = nil
end
loop.attach(timeout_timer)
timeout_timer
end

puts "start."

$start = Time.now
$timers = []
$loop = Cool.io::Loop.default
$times.times do
$timers << add_timeout_timer($loop)
end

$timeout_before = Time.now
timeout_timer = Coolio::TimerWatcher.new(1)
timeout_timer.on_timer do
$timeout_after = Time.now

timeout_timer.detach
$timers.each do |timer|
timer.detach
end

$finish = Time.now
delta = $finish - $start
delta -= $timeout_after - $timeout_before
puts "done."
puts "overhead: #{delta} seconds for #{$times} timers."
end
$loop.attach(timeout_timer)

$loop.run


0 comments on commit bad290c

Please sign in to comment.