Sha256: 6e0f45a95b2c4a3a0a8984d23b295b676732792b922f2c0862169c74aa78e960

Contents?: true

Size: 1.01 KB

Versions: 7

Compression:

Stored size: 1.01 KB

Contents

#!/usr/bin/env ruby

require '../ext/gmp'

multiplicands = ARGV
random_state = GMP::RandState.new

if multiplicands.size > 1
  m, n = multiplicands[0].to_i, multiplicands[1].to_i
  x = random_state.urandomb(m)
  y = random_state.urandomb(n)
else
  m = multiplicands[0].to_i
  x = random_state.urandomb(m)
  y = x
end

t = GMP::time { z = x * y }
iterations = (1 + (1e4 / t)).to_i

if multiplicands.size > 1
  print "Multiplying %i-bit number with %i-bit number %i times..." % [m, n, iterations]
else
  print "Squaring a %i-bit number %i times..." % [m, iterations]
end
STDOUT.flush

t0 = GMP::cputime
#iterations.times do
#  z = x * y
#end
parts = 512
foo = iterations / parts
bar = iterations % parts
foo.times do
  parts.times do
    z = x * y
  end
  GC.start
end
bar.times do
  z = x * y
end

ti = GMP::cputime - t0
  
puts "done!"
ops_per_sec = 1000.0 * iterations / ti
f = 100.0
decimals = 0
while true
  decimals += 1
  break if ops_per_sec > f
  f = f * 0.1
end

puts "RESULT: %#{decimals}f operations per second\n" % ops_per_sec

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
gmp-0.5.47 benchmark/multiply.gc
gmp-0.5.41 benchmark/multiply.gc
gmp-0.5.41-x86-mingw32 benchmark/multiply.gc
gmp-0.5.23 benchmark/multiply.gc
gmp-0.5.23-x86-mingw32 benchmark/multiply.gc
gmp-0.5.3 benchmark/multiply.gc
gmp-0.5.3-x86-mingw32 benchmark/multiply.gc