/* multiply.c -- benchmark plain integer multiplication. Copyright 2003 Free Software Foundation, Inc. This file is part of MPIRbench. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include #include "mpir.h" #include "timing.h" int main (int argc, char *argv[]) { gmp_randstate_t rs; mpz_t x, y, z; unsigned long int m, n, i, j, niter, t0, ti; double t, f, ops_per_sec; int decimals; if (argc != 3) { fprintf (stderr, "usage: %s m n\n", argv[0]); fprintf (stderr, " where m and n are number of bits in numbers tested\n"); return -1; } m = atoi (argv[1]); n = atoi (argv[2]); gmp_randinit_default (rs); mpz_init (x); mpz_init (y); mpz_init (z); mpz_urandomb (x, rs, m); mpz_urandomb (y, rs, n); // gmp_printf("%Zd\n", x); // gmp_printf("%Zd\n", y); printf ("Calibrating CPU speed..."); fflush (stdout); TIME (t, mpz_mul (z, x, y)); printf ("done\n"); niter = 1 + (unsigned long) (1e4 / t); printf ("Multiplying %lu-bit number with %lu-bit number %lu times...", m, n, niter); fflush (stdout); t0 = cputime (); mpz_urandomb (x, rs, m); mpz_urandomb (y, rs, n); for (i = niter; i > 0; i--) { mpz_mul (z, x, y); } ti = cputime () - t0; printf ("done!\n"); ops_per_sec = 1000.0 * niter / ti; f = 100.0; for (decimals = 0;; decimals++) { if (ops_per_sec > f) break; f = f * 0.1; } printf ("RESULT: %.*f operations per second\n", decimals, ops_per_sec); return 0; }