Sha256: 9d228a7617d28eabe7019ed71ff2126b0c3acd94f647c49046ae521a45cfc340

Contents?: true

Size: 917 Bytes

Versions: 1

Compression:

Stored size: 917 Bytes

Contents

#!/usr/bin/env ruby

require 'rubygems'
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '../lib')
require 'zipfian'
require 'test-unit'
require 'benchmark'
require 'parallelize'

class TestZipfian < Test::Unit::TestCase
  def test_zipfian_performance
    cnt = 100000

    [8, 4, 2, 1].each do |thr|
      puts "# of threads: #{thr}"
      zps = Array.new(thr)
      (2..6).each do |pow|
        max = 10 ** pow

        puts "Range: 1 ~ #{max}"
        print "Initialize (sec): "
        puts Benchmark.measure {
          thr.times.peach(thr) do |idx|
            zps[idx] = Zipfian.new max, 1, true
          end
        }.real

        print "Sample throughput (op/sec): "
        puts cnt / Benchmark.measure {
          thr.times.peach(thr) do |idx|
            cnt.times do |i|
              zps[idx].sample
            end
          end
        }.real
        puts
      end
      puts
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
zipfian-0.0.3 test/test_zipfian_perf.rb