#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

#include "fixpt.h"

#define  FUNC  takefraction
#define zFUNC ztakefraction

int inputs;
int *input;

int aritherror;

unsigned
timetest (int (*func) (int, int))
{
  int n, m;
  clock_t cl = clock ();

  for (n = 0; n < inputs; n++)
    for (m = 0; m < inputs - 1; m++)
      func (input[n], input[m]);

  return clock () - cl;
}

int
main ()
{
  int n, m;

  inputs = 32 * 32 + 1;		/* The last input being 0 */
  input = calloc (inputs, sizeof (*input));
  assert (input);

  for (n = 0; n < 32; n++)
    for (m = 0; m < 32; m++)
      input[n * 32 + m] = (1 << n) | (1 << m);

#if 0
  for (n = 0; n < inputs; n++)
    {
      for (m = 0; m < inputs - 1; m++)
	{
	  int o1 = FUNC (input[n], input[m]);
	  int o2 = zFUNC (input[n], input[m]);
	  if (o1 != o2)
	    printf ("%08x , %08x => %08x / %08x\n", input[n], input[m], o1, o2);
	}
    }
#else
  printf ("timing FUNC()  ");
  printf ("%ucs\n", timetest (FUNC));
  printf ("timing zFUNC() ");
  printf ("%ucs\n", timetest (zFUNC));
#endif
}
