From 3fd83cb6fcc483d2eac0795bc139c521a3a59bd2 Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Wed, 5 Jun 2019 16:32:27 +1200 Subject: Improve benchmarks and tests for threads. --- benchmark/vm_thread_alive_check.yml | 8 ++++++++ benchmark/vm_thread_alive_check1.rb | 6 ------ benchmark/vm_thread_pass.rb | 4 ++-- benchmark/vm_thread_pass_flood.rb | 4 ++-- benchmark/vm_thread_queue.rb | 2 +- benchmark/vm_thread_sleep.yml | 4 ++++ bootstraptest/test_thread.rb | 3 +++ 7 files changed, 20 insertions(+), 11 deletions(-) create mode 100644 benchmark/vm_thread_alive_check.yml delete mode 100644 benchmark/vm_thread_alive_check1.rb create mode 100644 benchmark/vm_thread_sleep.yml diff --git a/benchmark/vm_thread_alive_check.yml b/benchmark/vm_thread_alive_check.yml new file mode 100644 index 0000000000..d21737d3e8 --- /dev/null +++ b/benchmark/vm_thread_alive_check.yml @@ -0,0 +1,8 @@ +benchmark: + vm_thread_alive_check: | + t = Thread.new{} + while t.alive? + Thread.pass + end +loop_count: 50_000 + diff --git a/benchmark/vm_thread_alive_check1.rb b/benchmark/vm_thread_alive_check1.rb deleted file mode 100644 index c993accdda..0000000000 --- a/benchmark/vm_thread_alive_check1.rb +++ /dev/null @@ -1,6 +0,0 @@ -5_000.times{ - t = Thread.new{} - while t.alive? - Thread.pass - end -} diff --git a/benchmark/vm_thread_pass.rb b/benchmark/vm_thread_pass.rb index b5b3c0bc85..e5f2352610 100644 --- a/benchmark/vm_thread_pass.rb +++ b/benchmark/vm_thread_pass.rb @@ -1,8 +1,8 @@ # Plenty Thtread.pass # A performance may depend on GVL implementation. -tmax = (ARGV.shift || 2).to_i -lmax = 200_000 / tmax +tmax = (ARGV.shift || 8).to_i +lmax = 400_000 / tmax (1..tmax).map{ Thread.new{ diff --git a/benchmark/vm_thread_pass_flood.rb b/benchmark/vm_thread_pass_flood.rb index a660aafc18..65df8e6154 100644 --- a/benchmark/vm_thread_pass_flood.rb +++ b/benchmark/vm_thread_pass_flood.rb @@ -1,10 +1,10 @@ # n.b. this is a good test for GVL when pinned to a single CPU -1000.times{ +5_000.times{ Thread.new{loop{Thread.pass}} } i = 0 -while i<10000 +while i<10_000 i += 1 end diff --git a/benchmark/vm_thread_queue.rb b/benchmark/vm_thread_queue.rb index 274ceda366..1dd3696a3c 100644 --- a/benchmark/vm_thread_queue.rb +++ b/benchmark/vm_thread_queue.rb @@ -1,6 +1,6 @@ require 'thread' -n = 1_000_000 +n = 10_000_000 q = Thread::Queue.new consumer = Thread.new{ while q.pop diff --git a/benchmark/vm_thread_sleep.yml b/benchmark/vm_thread_sleep.yml new file mode 100644 index 0000000000..96901d8466 --- /dev/null +++ b/benchmark/vm_thread_sleep.yml @@ -0,0 +1,4 @@ +benchmark: + vm_thread_sleep: | + Thread.new { sleep } +loop_count: 10_000 diff --git a/bootstraptest/test_thread.rb b/bootstraptest/test_thread.rb index d16295de8b..854065f87e 100644 --- a/bootstraptest/test_thread.rb +++ b/bootstraptest/test_thread.rb @@ -10,6 +10,9 @@ assert_equal %q{ok}, %q{ :ok }.value } +assert_equal %q{ok}, %q{ + :ok if Thread.new{sleep}.backtrace == [] +} assert_equal %q{ok}, %q{ begin v = 0 -- cgit v1.2.3