aboutsummaryrefslogtreecommitdiffstats
path: root/benchmark
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-04-30 07:24:36 +0000
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-04-30 07:24:36 +0000
commitc373b8e56673d2934816d508ce3e6bbbab749e4b (patch)
treea290c6f357b61f93f77a22cc74d229b4bfa33590 /benchmark
parent711d988b42c4724bd087dae58442c78933c13948 (diff)
downloadruby-c373b8e56673d2934816d508ce3e6bbbab749e4b.tar.gz
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')
-rw-r--r--benchmark/bm_vm_thread_sized_queue.rb19
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