diff options
author | Samuel Williams <[email protected]> | 2019-06-05 16:32:27 +1200 |
---|---|---|
committer | Samuel Williams <[email protected]> | 2019-06-19 20:39:10 +1200 |
commit | 3fd83cb6fcc483d2eac0795bc139c521a3a59bd2 (patch) | |
tree | 775fa3b051fa2a50adbc994aeef82d9b2dc2c482 | |
parent | a6a4e86029f16415767b579e62691f09b1fb6075 (diff) |
Improve benchmarks and tests for threads.
-rw-r--r-- | benchmark/vm_thread_alive_check.yml | 8 | ||||
-rw-r--r-- | benchmark/vm_thread_alive_check1.rb | 6 | ||||
-rw-r--r-- | benchmark/vm_thread_pass.rb | 4 | ||||
-rw-r--r-- | benchmark/vm_thread_pass_flood.rb | 4 | ||||
-rw-r--r-- | benchmark/vm_thread_queue.rb | 2 | ||||
-rw-r--r-- | benchmark/vm_thread_sleep.yml | 4 | ||||
-rw-r--r-- | bootstraptest/test_thread.rb | 3 |
7 files changed, 20 insertions, 11 deletions
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 @@ -11,6 +11,9 @@ assert_equal %q{ok}, %q{ }.value } assert_equal %q{ok}, %q{ + :ok if Thread.new{sleep}.backtrace == [] +} +assert_equal %q{ok}, %q{ begin v = 0 (1..200).map{|i| |