mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Improved fiber benchmarks. Increase number of iterations.
This commit is contained in:
parent
8745fa2ff0
commit
012e954b47
8 changed files with 106 additions and 62 deletions
|
@ -1,40 +0,0 @@
|
|||
# Check performance of fiber creation and transfer.
|
||||
|
||||
def make_link(previous)
|
||||
Fiber.new do
|
||||
while message = previous.resume
|
||||
Fiber.yield(message)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def make_chain(length, &block)
|
||||
chain = Fiber.new(&block)
|
||||
|
||||
(length - 1).times do
|
||||
chain = make_link(chain)
|
||||
end
|
||||
|
||||
return chain
|
||||
end
|
||||
|
||||
def run_benchmark(length, repeats, message = :hello)
|
||||
chain = nil
|
||||
|
||||
chain = make_chain(length) do
|
||||
while true
|
||||
Fiber.yield(message)
|
||||
end
|
||||
end
|
||||
|
||||
repeats.times do
|
||||
abort "invalid result" unless chain.resume == message
|
||||
end
|
||||
end
|
||||
|
||||
n = (ARGV[0] || 1000).to_i
|
||||
m = (ARGV[1] || 1000).to_i
|
||||
|
||||
5.times do
|
||||
run_benchmark(n, m)
|
||||
end
|
36
benchmark/fiber_chain.yml
Executable file
36
benchmark/fiber_chain.yml
Executable file
|
@ -0,0 +1,36 @@
|
|||
prelude: |
|
||||
def make_link(previous)
|
||||
Fiber.new do
|
||||
while message = previous.resume
|
||||
Fiber.yield(message)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def make_chain(length = 1000, &block)
|
||||
chain = Fiber.new(&block)
|
||||
|
||||
(length - 1).times do
|
||||
chain = make_link(chain)
|
||||
end
|
||||
|
||||
return chain
|
||||
end
|
||||
|
||||
message = "Hello World!"
|
||||
|
||||
chain = make_chain do
|
||||
while true
|
||||
Fiber.yield(message)
|
||||
end
|
||||
end
|
||||
benchmark:
|
||||
make_chain: |
|
||||
make_chain(100) do
|
||||
while true
|
||||
Fiber.yield(message)
|
||||
end
|
||||
end
|
||||
resume_chain: |
|
||||
chain.resume
|
||||
loop_count: 5000
|
8
benchmark/vm2_fiber_allocate.yml
Normal file
8
benchmark/vm2_fiber_allocate.yml
Normal file
|
@ -0,0 +1,8 @@
|
|||
prelude: |
|
||||
# Disable GC to see raw throughput:
|
||||
GC.disable
|
||||
benchmark:
|
||||
vm2_fiber_allocate: |
|
||||
fiber = Fiber.new{Fiber.yield}
|
||||
fiber.resume
|
||||
loop_count: 100000
|
8
benchmark/vm2_fiber_count.yml
Normal file
8
benchmark/vm2_fiber_count.yml
Normal file
|
@ -0,0 +1,8 @@
|
|||
prelude: |
|
||||
fibers = []
|
||||
benchmark:
|
||||
vm2_fiber_count: |
|
||||
fiber = Fiber.new{Fiber.yield}
|
||||
fibers << fiber
|
||||
fiber.resume
|
||||
loop_count: 100000
|
14
benchmark/vm2_fiber_reuse.yml
Normal file
14
benchmark/vm2_fiber_reuse.yml
Normal file
|
@ -0,0 +1,14 @@
|
|||
prelude: |
|
||||
GC.disable
|
||||
fibers = []
|
||||
benchmark:
|
||||
vm2_fiber_reuse: |
|
||||
1024.times do
|
||||
fiber = Fiber.new{Fiber.yield}
|
||||
fibers << fiber
|
||||
fiber.resume
|
||||
end
|
||||
|
||||
fibers.clear
|
||||
GC.start
|
||||
loop_count: 200
|
|
@ -6,4 +6,4 @@ prelude: |
|
|||
benchmark:
|
||||
vm2_fiber_switch: |
|
||||
fib.resume
|
||||
loop_count: 6000000
|
||||
loop_count: 20000000
|
||||
|
|
39
bootstraptest/test_fiber.rb
Normal file
39
bootstraptest/test_fiber.rb
Normal file
|
@ -0,0 +1,39 @@
|
|||
show_limit %q{
|
||||
fibers = []
|
||||
begin
|
||||
fiber = Fiber.new{Fiber.yield}
|
||||
fiber.resume
|
||||
fibers << fiber
|
||||
|
||||
raise Exception, "skipping" if fibers.count >= 10_000
|
||||
rescue Exception => error
|
||||
puts "Fiber count: #{fibers.count} (#{error})"
|
||||
break
|
||||
end while true
|
||||
}
|
||||
|
||||
assert_equal %q{ok}, %q{
|
||||
Fiber.new{
|
||||
}.resume
|
||||
:ok
|
||||
}
|
||||
|
||||
assert_equal %q{ok}, %q{
|
||||
10_000.times.collect{Fiber.new{}}
|
||||
:ok
|
||||
}
|
||||
|
||||
assert_equal %q{ok}, %q{
|
||||
fibers = 100.times.collect{Fiber.new{Fiber.yield}}
|
||||
fibers.each(&:resume)
|
||||
fibers.each(&:resume)
|
||||
:ok
|
||||
}
|
||||
|
||||
assert_normal_exit %q{
|
||||
at_exit { Fiber.new{}.resume }
|
||||
}
|
||||
|
||||
assert_normal_exit %q{
|
||||
Fiber.new(&Object.method(:class_eval)).resume("foo")
|
||||
}, '[ruby-dev:34128]'
|
|
@ -9,19 +9,6 @@ show_limit %q{
|
|||
break
|
||||
end while true
|
||||
}
|
||||
show_limit %q{
|
||||
fibers = []
|
||||
begin
|
||||
fiber = Fiber.new{Fiber.yield}
|
||||
fiber.resume
|
||||
fibers << fiber
|
||||
|
||||
raise Exception, "skipping" if fibers.count >= 10_000
|
||||
rescue Exception => error
|
||||
puts "Fiber count: #{fibers.count} (#{error})"
|
||||
break
|
||||
end while true
|
||||
}
|
||||
assert_equal %q{ok}, %q{
|
||||
Thread.new{
|
||||
}.join
|
||||
|
@ -323,10 +310,6 @@ assert_equal 'ok', %q{
|
|||
m
|
||||
}, '[ruby-dev:34492]'
|
||||
|
||||
assert_normal_exit %q{
|
||||
at_exit { Fiber.new{}.resume }
|
||||
}
|
||||
|
||||
assert_normal_exit %q{
|
||||
g = enum_for(:local_variables)
|
||||
loop { g.next }
|
||||
|
@ -352,10 +335,6 @@ assert_normal_exit %q{
|
|||
loop { g.next }
|
||||
}, '[ruby-dev:34128]'
|
||||
|
||||
assert_normal_exit %q{
|
||||
Fiber.new(&Object.method(:class_eval)).resume("foo")
|
||||
}, '[ruby-dev:34128]'
|
||||
|
||||
assert_normal_exit %q{
|
||||
Thread.new("foo", &Object.method(:class_eval)).join
|
||||
}, '[ruby-dev:34128]'
|
||||
|
|
Loading…
Reference in a new issue