/*
 * $Header: /home/gene/library/website/docsrc/wgc/wgcperf/RCS/this.c,v 395.1 2008/04/20 17:25:48 gene Exp $
 */

#include "this.h"

long memory_size = 128 * 1024 * 1024;   /* 128 megabytes */

long
Iterations (long periter)
{
  return 12 * memory_size / periter;
}

static char *
S_TimeStr (clock_t ticks)
{
  static char str[1024];

  double cps = CLOCKS_PER_SEC;
  double sec = ticks / cps;
  int min = 0;
  int hr = 0;

  if (sec > 60.0) {
    min = sec / 60.0;
    sec -= min * 60;
    if (min > 60) {
      hr = min / 60;
      min %= 60;
      sprintf (str, "%d:%02d:%4.1f", hr, min, sec);
    } else {
      sprintf (str, "%02d:%4.1f", min, sec);
    }
  } else {
    sprintf (str, "%4.1f", sec);
  }
    return str;
}

static double
S_PerSec (clock_t ticks, long count)
{
  double rate = 0.0;
  double cps = CLOCKS_PER_SEC;

  if (count > 0) {
    rate = count * cps / ticks;
  }
  return rate;
}

void
ReportLine (clock_t automatic, clock_t manual, long count, char comment[],
            char name[])
{
  FILE *fp;

  fp = fopen ("raw.tex", "a");
  assert (fp != NULL);
  fprintf (fp, "\n{\\tt %s}", S_TimeStr (manual));
  fprintf (fp, " & {\\tt %s}", S_TimeStr (automatic));
  fprintf (fp, " & {\\tt %ld}", count);
  fprintf (fp, " & %s", name);
  fprintf (fp, " & %s \\\\ \\hline", comment);
  fclose (fp);

  fp = fopen ("rate.tex", "a");
  assert (fp != NULL);
  fprintf (fp, "\n{\\tt %.1e}", S_PerSec (manual, count));
  fprintf (fp, " & {\\tt %.1e}", S_PerSec (automatic, count));
  fprintf (fp, " & %s", name);
  fprintf (fp, " & %s \\\\ \\hline", comment);
  fclose (fp);
}

/* --- end of file --- */
