1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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