#!/usr/bin/env ruby require '../ext/gmp' dividend = ARGV[0].to_i divisor = ARGV[1].to_i random_state = GMP::RandState.new x = random_state.urandomb(dividend) y = random_state.urandomb(divisor) t = GMP::time { z = x.tdiv y } iterations = (1 + (1e4 / t)).to_i print "Dividing an %i-bit number by an %i-bit number %i times..." % [dividend, divisor, iterations] STDOUT.flush t0 = GMP::cputime iterations.times do z = x.tdiv 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