Created
April 4, 2013 21:31
-
-
Save jstorimer/5314556 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
require 'benchmark' | |
require 'thread' | |
require 'disruptor' | |
require_relative 'atomic_linked_queue' | |
$thread_count = 50 | |
$iterations = 10 | |
Thread.abort_on_exception = true | |
# this one tells all the threads when to start | |
$go = false | |
def setup(queue) | |
tg = ThreadGroup.new | |
$thread_count.times do | |
t = Thread.new do | |
# wait until the bm starts to do the work. This should | |
# minimize variance. | |
nil until $go | |
$iterations.times do | |
queue.push(:item) | |
end | |
$iterations.times do | |
queue.pop | |
end | |
end | |
tg.add(t) | |
end | |
tg | |
end | |
def exercise(tg) | |
$go = true | |
tg.list.each(&:join) | |
$go = false | |
end | |
Benchmark.bm(50) do |bm| | |
queue = Queue.new | |
tg = setup(queue) | |
bm.report("Queue (stdlib)") { exercise(tg) } | |
atomic = AtomicLinkedQueue.new | |
tg = setup(atomic) | |
bm.report("AtomicLinkedQueue") { exercise(tg) } | |
disruptor_spinning = Disruptor::Queue.new($iterations * $thread_count, Disruptor::BusySpinWaitStrategy.new) | |
tg = setup(disruptor_spinning) | |
bm.report("Disruptor::Queue - BusySpinWaitStrategy") { exercise(tg) } | |
#disruptor_blocking = Disruptor::Queue.new($iterations * $thread_count + 2, Disruptor::BlockingWaitStrategy.new) | |
#tg = setup(disruptor_blocking) | |
#bm.report("Disruptor::Queue - BlockingWaitStrategy") { exercise(tg) } | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment