Back to index

lightning-sunbird  0.9+nobinonly
Classes | Functions | Variables
mptest-4b.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <time.h>
#include <sys/time.h>
#include "mpi.h"
#include "mpprime.h"

Go to the source code of this file.

Classes

struct  instant_t

Functions

instant_t now (void)
mp_err s_mp_pad ()
int main (int argc, char *argv[])

Variables

char * g_prime = "23B54EE961A8C69CD625CE4EC38B70C649D7F014432AEF3A1C93"
char * g_gen = "5"

Class Documentation

struct instant_t

Definition at line 52 of file mptest-4a.c.

Class Members
unsigned int sec
unsigned int usec

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 85 of file mptest-4b.c.

{
  instant_t    start, finish;
  mp_int       prime, gen, expt, res;
  unsigned int ix, diff;
  int          num;

  srand(time(NULL));

  if(argc < 2) {
    fprintf(stderr, "Usage: %s <num-tests>\n", argv[0]);
    return 1;
  }

  if((num = atoi(argv[1])) < 0)
    num = -num;

  if(num == 0)
    ++num;

  mp_init(&prime); mp_init(&gen); mp_init(&res);
  mp_read_radix(&prime, g_prime, 16);
  mp_read_radix(&gen, g_gen, 16);

  mp_init_size(&expt, USED(&prime) - 1);
  s_mp_pad(&expt, USED(&prime) - 1);

  printf("Testing %d modular exponentations ... \n", num);

  start = now();
  for(ix = 0; ix < num; ix++) {
    mpp_random(&expt);
    mp_exptmod(&gen, &expt, &prime, &res);
  }
  finish = now();

  diff = (finish.sec - start.sec) * 1000000;
  diff += finish.usec; diff -= start.usec;

  printf("%d operations took %u usec (%.3f sec)\n",
        num, diff, (double)diff / 1000000.0);
  printf("That is %.3f sec per operation.\n",
        ((double)diff / 1000000.0) / num);

  mp_clear(&expt);
  mp_clear(&res);
  mp_clear(&gen);
  mp_clear(&prime);

  return 0;
}

Here is the call graph for this function:

Definition at line 67 of file mptest-4b.c.

{
  struct timeval clk;
  instant_t      res;

  res.sec = res.usec = 0;

  if(gettimeofday(&clk, NULL) != 0)
    return res;

  res.sec = clk.tv_sec;
  res.usec = clk.tv_usec;

  return res;
}

Here is the call graph for this function:


Variable Documentation

char* g_gen = "5"

Definition at line 60 of file mptest-4b.c.

char* g_prime = "23B54EE961A8C69CD625CE4EC38B70C649D7F014432AEF3A1C93"

Definition at line 55 of file mptest-4b.c.