summaryrefslogtreecommitdiff
path: root/benchmark/fiber_chain.yml
blob: a36c759f8efa8eb666c9774765664edf71185161 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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