Sha256: ea8b35111a9c4555f3c9bc45480cdfe23a3c4bd7ff6b2fe1cd129b62e9241dfa

Contents?: true

Size: 758 Bytes

Versions: 84

Compression:

Stored size: 758 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_threads)
  count = 0

  GC.start
  GC.disable

  threads = []
  t0 = Time.now
  limit = 10_000_000 / num_threads
  num_threads.times do
    threads << Thread.new do
      individual_count = 0
      loop do
        individual_count += 1
        count += 1
        break if individual_count == limit
      end
    end
  end

  threads.each(&:join)
  elapsed = Time.now - t0

  puts "threads: #{num_threads} count: #{count} rate: #{count / elapsed}"
rescue Exception => e
  puts "Stopped at #{count} threads"
  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/thread_switch.rb
polyphony-1.5 examples/performance/thread_switch.rb
polyphony-1.4 examples/performance/thread_switch.rb
polyphony-1.3 examples/performance/thread_switch.rb
polyphony-1.2.1 examples/performance/thread_switch.rb
polyphony-1.2 examples/performance/thread_switch.rb
polyphony-1.1.1 examples/performance/thread_switch.rb
polyphony-1.1 examples/performance/thread_switch.rb
polyphony-1.0.2 examples/performance/thread_switch.rb
polyphony-1.0.1 examples/performance/thread_switch.rb
polyphony-1.0 examples/performance/thread_switch.rb
polyphony-0.99.6 examples/performance/thread_switch.rb
polyphony-0.99.5 examples/performance/thread_switch.rb
polyphony-0.99.4 examples/performance/thread_switch.rb
polyphony-0.99.3 examples/performance/thread_switch.rb
polyphony-0.99.2 examples/performance/thread_switch.rb
polyphony-0.99.1 examples/performance/thread_switch.rb
polyphony-0.99 examples/performance/thread_switch.rb
polyphony-0.98 examples/performance/thread_switch.rb
polyphony-0.97 examples/performance/thread_switch.rb