/* * main * if there are no arguments, run interactively, otherwise, run a program * from within the shell, but immediately exit. */ int main(int argc, char *argv[]) { #ifdef HOST hostcompat_init(argc, argv); #endif check_timing(); /* * Allow argc to be 0 in case we're running on a broken kernel, * or one that doesn't set argv when starting the first shell. */ if (argc == 0 || argc == 1) { interactive(); } else if (argc == 3 && !strcmp(argv[1], "-c")) { return docommand(argv[2]); } else { errx(1, "Usage: sh [-c command]"); } return 0; }
void timing_modular(int bits) { SshIntModQ b, c, d, e, f[100]; SshIntModuli m; SshInt a; int i, j; TimeIt tmit; ssh_mp_init(&a); do { ssh_mp_rand(&a, bits); while (ssh_mp_next_prime(&a, &a) == FALSE) ssh_mp_rand(&a, bits); } while (ssh_mp_get_size(&a, 2) < bits - 1); printf("Timing modular arithmetic.\n"); if (ssh_mpm_init_m(&m, &a) == FALSE) ssh_fatal("timing_modular: could not initialize modular arithmetic."); printf("Bits = %u\n", bits); ssh_mpm_init(&b, &m); ssh_mpm_init(&c, &m); ssh_mpm_init(&d, &m); ssh_mpm_init(&e, &m); for (i = 0; i < 100; i++) { ssh_mpm_init(&f[i], &m); ssh_mp_rand(&a, bits); ssh_mpm_set_mp(&f[i], &a); } printf("Timing multiplication [%u * %u = %u] \n", bits, bits, bits); start_timing(&tmit); for (i = 0; i < 50; i++) { ssh_mpm_set(&b, &f[i]); for (j = 0; j < 100; j++) ssh_mpm_mul(&c, &f[j], &b); } check_timing(&tmit); printf(" * %g multiplications per sec (%g cycles)\n", ((double)50*100)/(tmit.real_secs), (double)tmit.cycles/(50*100.0)); printf("Timing squarings [%u^2 = %u] \n", bits, bits); start_timing(&tmit); for (i = 0; i < 50; i++) for (j = 0; j < 100; j++) ssh_mpm_square(&b, &f[j]); check_timing(&tmit); printf(" * %g squarings per sec (%g cycles)\n", ((double)50*100)/(tmit.real_secs), (double)tmit.cycles/(50*100.0)); ssh_mpm_clear(&b); ssh_mpm_clear(&c); ssh_mpm_clear(&d); ssh_mpm_clear(&e); for (i = 0; i < 100; i++) ssh_mpm_clear(&f[i]); ssh_mpm_clear_m(&m); ssh_mp_clear(&a); }
/* * Regularly create, open a cursor and drop a table. * Measure how long each step takes, and flag an error if it exceeds the * configured maximum. */ static void * cycle_idle_tables(void *arg) { struct timespec start, stop; CONFIG *cfg; WT_SESSION *session; WT_CURSOR *cursor; int cycle_count, ret; char uri[512]; cfg = (CONFIG *)arg; cycle_count = 0; if ((ret = cfg->conn->open_session( cfg->conn, NULL, cfg->sess_config, &session)) != 0) { lprintf(cfg, ret, 0, "Error opening a session on %s", cfg->home); return (NULL); } for (cycle_count = 0; cfg->idle_cycle_run; ++cycle_count) { snprintf(uri, 512, "%s_cycle%07d", cfg->uris[0], cycle_count); /* Don't busy cycle in this loop. */ __wt_sleep(1, 0); /* Setup a start timer. */ if ((ret = __wt_epoch(NULL, &start)) != 0) { lprintf(cfg, ret, 0, "Get time failed in cycle_idle_tables."); cfg->error = ret; return (NULL); } /* Create a table. */ if ((ret = session->create( session, uri, cfg->table_config)) != 0) { if (ret == EBUSY) continue; lprintf(cfg, ret, 0, "Table create failed in cycle_idle_tables."); cfg->error = ret; return (NULL); } if (check_timing(cfg, "create", start, &stop) != 0) return (NULL); start = stop; /* Open and close cursor. */ if ((ret = session->open_cursor( session, uri, NULL, NULL, &cursor)) != 0) { lprintf(cfg, ret, 0, "Cursor open failed in cycle_idle_tables."); cfg->error = ret; return (NULL); } if ((ret = cursor->close(cursor)) != 0) { lprintf(cfg, ret, 0, "Cursor close failed in cycle_idle_tables."); cfg->error = ret; return (NULL); } if (check_timing(cfg, "cursor", start, &stop) != 0) return (NULL); start = stop; /* * Drop the table. Keep retrying on EBUSY failure - it is an * expected return when checkpoints are happening. */ while ((ret = session->drop( session, uri, "force,checkpoint_wait=false")) == EBUSY) __wt_sleep(1, 0); if (ret != 0 && ret != EBUSY) { lprintf(cfg, ret, 0, "Table drop failed in cycle_idle_tables."); cfg->error = ret; return (NULL); } if (check_timing(cfg, "drop", start, &stop) != 0) return (NULL); } return (NULL); }
void timing_int(int bits) { SshInt a, b, c, d, e, f[100]; TimeIt tmit; unsigned int i, j; SshMpPowmBase base; ssh_mp_init(&a); ssh_mp_init(&b); ssh_mp_init(&c); ssh_mp_init(&d); ssh_mp_init(&e); printf("Timing integer arithmetic.\n"); printf("Bits = %u\n", bits); for (i = 0; i < 100; i++) { ssh_mp_init(&f[i]); ssh_mp_rand(&f[i], bits); if ((ssh_mp_get_ui(&f[i]) & 0x1) == 0) ssh_mp_add_ui(&f[i], &f[i], 1); } printf("Timing multiplication [%u * %u = %u] \n", bits, bits, bits + bits); start_timing(&tmit); for (i = 0; i < 50; i++) { ssh_mp_rand(&b, bits); for (j = 0; j < 100; j++) ssh_mp_mul(&a, &f[j], &b); } check_timing(&tmit); printf(" * %g multiplications per sec (%g cycles)\n", ((double)50*100)/(tmit.real_secs), (double)tmit.cycles/(50*100.0)); printf("Timing divisions [%u / %u = %u] \n", bits + bits, bits, bits); start_timing(&tmit); for (i = 0; i < 50; i++) { ssh_mp_rand(&b, bits*2); for (j = 0; j < 100; j++) ssh_mp_div(&a, &c, &b, &f[j]); } check_timing(&tmit); printf(" * %g divisions per sec (%g cycles)\n", ((double)50*100)/(tmit.real_secs), (double)tmit.cycles/(50*100.0)); printf("Timing modular reductions [%u %% %u = %u] \n", bits + bits, bits, bits); start_timing(&tmit); for (i = 0; i < 50; i++) { ssh_mp_rand(&b, bits*2); for (j = 0; j < 100; j++) ssh_mp_mod(&a, &b, &f[j]); } check_timing(&tmit); printf(" * %g modular reductions per sec (%g cycles)\n", ((double)50*100)/(tmit.real_secs), (double)tmit.cycles/(50*100.0)); printf("Timing squarings [%u^2 = %u] \n", bits, bits + bits); start_timing(&tmit); for (i = 0; i < 50; i++) { ssh_mp_rand(&b, bits); for (j = 0; j < 100; j++) ssh_mp_square(&a, &b); } check_timing(&tmit); printf(" * %g squarings per sec (%g cycles)\n", ((double)50*100)/(tmit.real_secs), (double)tmit.cycles/(50*100.0)); printf("Timing modexp [%u^%u %% %u = %u] \n", bits, bits, bits, bits); start_timing(&tmit); for (j = 0, i = 0; i < 10; i++, j += 2) { ssh_mp_rand(&b, bits); ssh_mp_powm(&a, &b, &f[j + 1], &f[j + 2]); } check_timing(&tmit); printf(" * %g modexps per sec (%g cycles)\n", ((double)10)/(tmit.real_secs), (double)tmit.cycles/(10.0)); /* Generate the fixed base. */ do { ssh_mp_rand(&b, bits); } while (ssh_mp_get_size(&b, 2) < bits-1); /* Create the base. */ ssh_mp_powm_with_base_init(&b, &f[2], &base); if (base.defined == FALSE) ssh_fatal("error: could not define base."); printf("Timing modexp with fixed base [%u^%u %% %u = %u] \n", bits, bits, bits, bits); start_timing(&tmit); for (j = 0, i = 0; i < 10; i++, j += 2) ssh_mp_powm_with_base(&a, &f[j + 1], &base); check_timing(&tmit); printf(" * %g modexps per sec (%g cycles)\n", ((double)10)/(tmit.real_secs), (double)tmit.cycles/(10.0)); ssh_mp_powm_with_base_clear(&base); #define ENTROPY_BITS 256 printf("Timing modexp [%u^%u %% %u = %u] \n", bits, ENTROPY_BITS, bits, bits); start_timing(&tmit); for (j = 0, i = 0; i < 10; i++, j += 2) { ssh_mp_rand(&b, ENTROPY_BITS); ssh_mp_set_bit(&b, ENTROPY_BITS); ssh_mp_powm(&a, &f[j+1], &b, &f[j + 2]); } check_timing(&tmit); printf(" * %g modexps per sec (%g cycles)\n", ((double)10)/(tmit.real_secs), (double)tmit.cycles/(10.0)); ssh_mp_clear(&a); ssh_mp_clear(&b); ssh_mp_clear(&c); ssh_mp_clear(&d); ssh_mp_clear(&e); for (i = 0; i < 100; i++) ssh_mp_clear(&f[i]); }