/*
   file chrono.c
   created nov. 1 2005 by Yann GUIDON <whygee@f-cpu.org>
   This program measures the speed of the CRC16 routines
   on 4K-blocks as used by the MDS container.

   version nov. 2 : Now testing contiguous blocks

   gcc -Os -fomit-frame-pointer -march={pentium3|...} -o chrono chrono.c
   for i in a b c d; do /usr/bin/time -f "%U" ./chrono ; done
*/

#include "mds_crc16.c"

#ifdef CRC16_MULTI   /* multi-threaded version */
/* FIXME: only CRC16_MULTI==2 is handled correctly */

#define LOOPS  (1000000 / CRC16_MULTI)
/* This amounts to 4096*10^6 = roughly 4GB */

unsigned char z[(4096+100)*CRC16_MULTI];

int main() {
  unsigned long int i, j, crc_res=0;

  j=0xFEDC;
  for (i=0; i<sizeof(z); i++) {
    j=i+ (CRC16_LUT[(U8)(j+i)] ^ (j >> 8));
    z[i]= (U8) j;
  }

  for (i=0; i<LOOPS; i++) {
    CRC16(z, 4096, z+4096+16, 4096);
    crc_res ^=crc_res_1^crc_res_2;
  }

  return crc_res;
}

#else     /* simple version */

#define LOOPS 1000000
/* idem : 4GB */

unsigned char z[4096];

int main() {
  unsigned long int i, j, crc_res=0;

  j=0xFEDC;
  for (i=0; i<sizeof(z); i++) {
    j=i+ (CRC16_LUT[(U8)(j+i)] ^ (j >> 8));
    z[i]= (U8) j;
  }

  for (i=0; i<LOOPS; i++) {
    crc_res ^= CRC16(z, 4096);
  }

  return crc_res;
}

#endif
