Sha256: 89ff544ab03cdad2511e53db3fffce829b1bf6022656a66bc8a86ecba90aabeb

Contents?: true

Size: 658 Bytes

Versions: 84

Compression:

Stored size: 658 Bytes

Contents

# frozen_string_literal: true

require 'fiber'

class Fiber
  attr_accessor :next
end

# This program shows how the performance of Fiber.transfer degrades as the fiber
# count increases

def run(num_fibers)
  count = 0

  GC.start
  GC.disable

  fibers = []
  num_fibers.times do
    fibers << Fiber.new { loop { Fiber.yield } }
  end

  t0 = Time.now

  while count < 1000000
    fibers.each do |f|
      count += 1
      f.resume
    end
  end

  elapsed = Time.now - t0

  puts "fibers: #{num_fibers} count: #{count} rate: #{count / elapsed}"
rescue Exception => e
  puts "Stopped at #{count} fibers"
  p e
end

run(100)
run(1000)
run(10000)
run(100000)

Version data entries

84 entries across 84 versions & 1 rubygems

Version Path
polyphony-1.6 examples/performance/fiber_resume.rb
polyphony-1.5 examples/performance/fiber_resume.rb
polyphony-1.4 examples/performance/fiber_resume.rb
polyphony-1.3 examples/performance/fiber_resume.rb
polyphony-1.2.1 examples/performance/fiber_resume.rb
polyphony-1.2 examples/performance/fiber_resume.rb
polyphony-1.1.1 examples/performance/fiber_resume.rb
polyphony-1.1 examples/performance/fiber_resume.rb
polyphony-1.0.2 examples/performance/fiber_resume.rb
polyphony-1.0.1 examples/performance/fiber_resume.rb
polyphony-1.0 examples/performance/fiber_resume.rb
polyphony-0.99.6 examples/performance/fiber_resume.rb
polyphony-0.99.5 examples/performance/fiber_resume.rb
polyphony-0.99.4 examples/performance/fiber_resume.rb
polyphony-0.99.3 examples/performance/fiber_resume.rb
polyphony-0.99.2 examples/performance/fiber_resume.rb
polyphony-0.99.1 examples/performance/fiber_resume.rb
polyphony-0.99 examples/performance/fiber_resume.rb
polyphony-0.98 examples/performance/fiber_resume.rb
polyphony-0.97 examples/performance/fiber_resume.rb