diff options
author | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-04-30 07:24:36 +0000 |
---|---|---|
committer | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-04-30 07:24:36 +0000 |
commit | 8e147f1b0d57dfb0498d6d83877622dc9c933dc1 (patch) | |
tree | a290c6f357b61f93f77a22cc74d229b4bfa33590 /benchmark/bm_vm_thread_sized_queue.rb | |
parent | 5a2c1ee3537c6a2b2661c13afde9c5b8a578ecbc (diff) |
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
Diffstat (limited to 'benchmark/bm_vm_thread_sized_queue.rb')
-rw-r--r-- | benchmark/bm_vm_thread_sized_queue.rb | 19 |
1 files changed, 19 insertions, 0 deletions
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 |