Sha256: 786792fde4b72837e4e8dbf5fafcb9b9e4195d31ab1d08a2964060c232c23d05

Contents?: true

Size: 878 Bytes

Versions: 7

Compression:

Stored size: 878 Bytes

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
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
gmp-0.5.41 benchmark/multiply
gmp-0.5.41-x86-mingw32 benchmark/multiply
gmp-0.5.23 benchmark/multiply
gmp-0.5.23-x86-mingw32 benchmark/multiply
gmp-0.5.3 benchmark/multiply
gmp-0.5.3-x86-mingw32 benchmark/multiply