From 8e147f1b0d57dfb0498d6d83877622dc9c933dc1 Mon Sep 17 00:00:00 2001 From: normal Date: Sun, 30 Apr 2017 07:24:36 +0000 Subject: [PATCH] new benchmark for SizedQueue The performance of SizedQueue is a bit more complex than regular Queue, so it deserves a separate benchmark. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58509 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- benchmark/bm_vm_thread_sized_queue.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 benchmark/bm_vm_thread_sized_queue.rb diff --git a/benchmark/bm_vm_thread_sized_queue.rb b/benchmark/bm_vm_thread_sized_queue.rb new file mode 100644 index 0000000000..ce15367aba --- /dev/null +++ b/benchmark/bm_vm_thread_sized_queue.rb @@ -0,0 +1,19 @@ +require 'thread' + +n = 1_000_000 +q = Thread::SizedQueue.new(100) +consumer = Thread.new{ + while q.pop + # consuming + end +} + +producer = Thread.new{ + while n > 0 + q.push true + n -= 1 + end + q.push nil +} + +consumer.join