/* Collection of code snippets by Arne Vajhøj */
/* (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) */
#include <stdio.h>
#include <string.h>
#include <time.h>

#include <gmp.h>

#define N1 1000000000
#define N2 10

int main(int argc, char *argv[])
{
    /* setup */
    mpz_t a, b, c;
    mpz_init_set_str(a, "123456789123456789123456789", 10);
    mpz_init_set_str(b, "987654321987654321987654321", 10);
    mpz_init(c);
    /* check functionality */
    mpz_mul(c, a, b);
    mpz_out_str(stdout, 10, c);
    printf("\n");
    mpz_div(c, c, b);    
    mpz_out_str(stdout, 10, c);
    printf("\n");
    /* check performance */
    time_t t1 = time(NULL);
    for(int j = 0; j < N2; j++)
    {
        for(int i = 0; i < N1; i++)
        {
            mpz_mul(c, a, b);
        }
    }
    time_t t2 = time(NULL);
    printf("%.0f bigmuls per second\n", N1 * 1.0 * N2 / (t2 - t1));
    /* cleanup */
    mpz_clear(a);
    mpz_clear(b);
    mpz_clear(c);
    return 0;
}
