48int main(
int argc,
char *argv[]) {
49 int do_mul = 0, do_exp = 0, do_header = 1;
50 int num_tests, precision = 0, opt;
52 unsigned int seed = (
unsigned int)time(NULL);
54 while ((opt = getopt(argc, argv,
"ehmnp:s:t:")) != EOF) {
66 precision = atoi(optarg);
72 threshold = (
mp_size)atoi(optarg);
76 "Usage: imtimer [options] <num-tests>\n\n"
77 "Options understood:\n"
78 " -e -- test modular exponentiation speed.\n"
79 " -h -- display this help message.\n"
80 " -m -- test multiplication speed.\n"
81 " -n -- no header line.\n"
82 " -p <dig> -- use values with <dig> digits.\n"
83 " -s <rnd> -- set random seed to <rnd>.\n"
84 " -t <dig> -- set recursion threshold to <dig> digits.\n\n");
91 "Usage: imtimer [options] <num-tests>\n"
92 "[use \"imtimer -h\" for help with options]\n\n");
95 num_tests = atoi(argv[optind]);
100 fprintf(stderr,
"You must request at least one test.\n");
104 fprintf(stderr,
"Precision must be non-negative (0 means default).\n");
109 if (do_header) printf(
"NUM\tPREC\tBITS\tREC\tRESULT\n");
110 printf(
"%d\t%d\t%d\t%u", num_tests, precision,
116 printf(
"\tMUL %.3f %.3f", m_time, m_time / num_tests);
122 printf(
"\tEXP %.3f %.3f", e_time, e_time / num_tests);
131 return (
double)(end - start) / CLOCKS_PER_SEC;
138 if (out == NULL)
return NULL;
140 for (i = 0; i < nt; ++i) {
169 if ((values =
alloc_values(3, prec)) == NULL)
return 0.0;
173 for (i = 0; i < nt; ++i)
mp_int_mul(values, values + 1, values + 2);
186 if ((values =
alloc_values(4, prec)) == NULL)
return 0.0;
190 for (i = 0; i < nt; ++i)
204 for (i = 0; i < prec; ++i) {
208 for (j = 0; j < (int)
sizeof(d); ++j) {
209 d = (d << CHAR_BIT) | (rand() & UCHAR_MAX);
void mp_int_multiply_threshold(mp_size thresh)
Sets the number of digits below which multiplication will use the standard quadratic "schoolbook" mul...
static mp_size MP_ALLOC(mp_int Z)
double clocks_to_seconds(clock_t start, clock_t end)
double get_multiply_time(int nt, int prec)
void randomize_values(mp_int values, int nt, int prec)
double get_exptmod_time(int nt, int prec)
mp_int alloc_values(int nt, int prec)
void mp_int_random(mp_int z, int prec)
void release_values(mp_int values, int nt)