Sha256: 819c3e6a44d2dd2a51eeee59715873aa622d8c425ecfb4ebd21f1624e6258db7

Contents?: true

Size: 1.24 KB

Versions: 31

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

require 'bundler/setup'
require 'polyphony'

def lengthy_op
  data = IO.orig_read(__FILE__)
  data.clear
  # Socket.getaddrinfo('debian.org', 80)
  # Digest::SHA256.digest(IO.read('doc/Promise.html'))
end

X = 100

def compare_performance
  t0 = Time.now
  X.times { lengthy_op }
  native_perf = X / (Time.now - t0)
  puts "native performance: #{native_perf}"
  # puts "*" * 40

  begin
    1.times do
      t0 = Time.now
      X.times do
        Polyphony::ThreadPool.process { lengthy_op }
      end
      async_perf = X / (Time.now - t0)
      puts format(
        'seq thread pool performance: %g (X %0.2f)',
        async_perf,
        async_perf / native_perf
      )
    end

    acc = 0
    count = 0
    10.times do |_i|
      t0 = Time.now
      supervise do |s|
        X.times do
          s.spin { Polyphony::ThreadPool.process { lengthy_op } }
        end
      end
      thread_pool_perf = X / (Time.now - t0)
      acc += thread_pool_perf
      count += 1
    end
    avg_perf = acc / count
    puts format(
      'avg thread pool performance: %g (X %0.2f)',
      avg_perf,
      avg_perf / native_perf
    )
  rescue Exception => e
    p e
    puts e.backtrace.join("\n")
  end
end

spin { compare_performance }

suspend

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
polyphony-0.45.0 examples/performance/thread_pool_perf.rb
polyphony-0.44.0 examples/performance/thread_pool_perf.rb
polyphony-0.43.11 examples/performance/thread_pool_perf.rb
polyphony-0.43.10 examples/performance/thread_pool_perf.rb
polyphony-0.43.9 examples/performance/thread_pool_perf.rb
polyphony-0.43.8 examples/performance/thread_pool_perf.rb
polyphony-0.43.6 examples/performance/thread_pool_perf.rb
polyphony-0.43.5 examples/performance/thread_pool_perf.rb
polyphony-0.43.4 examples/performance/thread_pool_perf.rb
polyphony-0.43.3 examples/performance/thread_pool_perf.rb
polyphony-0.43.2 examples/performance/thread_pool_perf.rb
polyphony-0.43.1 examples/performance/thread_pool_perf.rb
polyphony-0.43 examples/performance/thread_pool_perf.rb
polyphony-0.42 examples/performance/thread_pool_perf.rb
polyphony-0.41 examples/performance/thread_pool_perf.rb
polyphony-0.40 examples/performance/thread_pool_perf.rb
polyphony-0.39 examples/performance/thread_pool_perf.rb
polyphony-0.38 examples/performance/thread_pool_perf.rb
polyphony-0.36 examples/performance/thread_pool_perf.rb
polyphony-0.34 examples/performance/thread_pool_perf.rb