Improve benchmarks and tests for threads.

This commit is contained in:
Samuel Williams 2019-06-05 16:32:27 +12:00
parent a6a4e86029
commit 3fd83cb6fc
7 changed files with 20 additions and 11 deletions

View File

@ -0,0 +1,8 @@
benchmark:
vm_thread_alive_check: |
t = Thread.new{}
while t.alive?
Thread.pass
end
loop_count: 50_000

View File

@ -1,6 +0,0 @@
5_000.times{
t = Thread.new{}
while t.alive?
Thread.pass
end
}

View File

@ -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{

View File

@ -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

View File

@ -1,6 +1,6 @@
require 'thread'
n = 1_000_000
n = 10_000_000
q = Thread::Queue.new
consumer = Thread.new{
while q.pop

View File

@ -0,0 +1,4 @@
benchmark:
vm_thread_sleep: |
Thread.new { sleep }
loop_count: 10_000

View File

@ -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