2019-06-02 04:48:47 +03:00
|
|
|
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
|
2019-07-12 11:57:28 +03:00
|
|
|
|
2019-06-02 04:48:47 +03:00
|
|
|
message = "Hello World!"
|
2019-07-12 11:57:28 +03:00
|
|
|
|
2019-06-02 04:48:47 +03:00
|
|
|
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
|