/* * 'test-speed.c' created: Tue Oct 15 22:55:06 2002 * * Copyright 2002 by Lubomir Host <8host AT pauli.fmph.uniba.sk> * * License: GNU GPL (GNU Public License) * * test speed of random generators */ /* $Platon$ */ #ifdef HAVE_CONFIG_H # include "config.h" #endif #include #include #include #include #include #include "main.h" #include "devices.h" #include "tests.h" #include "time.h" #include "test-speed.h" #define move_speed(_speed, _size, _i) \ for (_i = 0; _i < (_size - 1); _i++) \ _speed[_i] = _speed[_i+1]; RNG_test_t RNG_test_speed = { "test for speed of generators", 2E4, test_speed }; /* static int test_converged(Real_t *speeds, int size) { int i; Real_t avg = 0.0; for (i = 0; i < size; i++) avg += speeds[i] / size; if (avg == 0.0) return RNG_FAIL; for (i = 0; i < size; i++) if (speeds[i] / avg > 1.2 || speeds[i] / avg < 0.8) return RNG_FAIL; return RNG_OK; } */ int test_speed(int *counts) { int j = 0; int retval = RNG_OK; Real_t speeds[] = { 0.0, 0.0, 0.0 }; struct timeval tv_first, tv_second, tv_diff; struct timezone tz_first, tz_second; while (rng_devices[j] != NULL) { int i = 0; int k = 0; int cur = 1; int end = counts[0]; printf("# @@ running test for R.N.G. %s\n", (*rng_devices[j]).desc); printf("# ** \n"); /* first rememeber actual time */ gettimeofday(&tv_first, &tz_first); while (counts[i] != -1 && end != -1 && counts[i] <= RNG_test_speed.max_count && counts[i] <= (*rng_devices[j]).max_count && retval == RNG_OK) { end = counts[i]; while ((cur - 1) != end && end != -1) { /* printf("cur = %d end = %d\n", cur, end); */ (*rng_devices[j]).read(); cur++; } gettimeofday(&tv_second, &tz_second); timersub_static(tv_second, tv_first, tv_diff); move_speed(speeds, 3, k); speeds[2] = 1.0 * counts[i] / (tv_diff.tv_sec + 1E-6*tv_diff.tv_usec); printf("%d\t%ld\t%ld\t%Lg", counts[i], tv_diff.tv_sec, tv_diff.tv_usec, speeds[2]); /* if (test_converged(speeds, 3) == RNG_OK) { printf(" (converged)\n"); end = -1; } else { */ printf("\n"); end = counts[++i + 1]; /* } */ } j++; } return retval; } /* Modeline for ViM {{{ * vim: set ts=4: * vim600: fdm=marker fdl=0 fdc=3: * }}} */