Sha256: ece383bd497fe93d67d2feba01dcb380e865d3ec424e2093f7bd9270b22a75c3

Contents?: true

Size: 1.2 KB

Versions: 1

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

require 'bundler/setup'
require 'polyphony'

def lengthy_op
  data = IO.read('../../docs/dev-journal.md')
  data.clear
  # Socket.getaddrinfo('debian.org', 80)
  #Digest::SHA256.digest(IO.read('doc/Promise.html'))
end

X = 1000

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 "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.coproc 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 "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 }

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
polyphony-0.19 examples/core/thread_pool.rb