static void Test14(void) { enum { NUM_KEYS = 1000000 }; static Key key[NUM_KEYS]; Tree t = { NULL }; Key a; VAR_SLICE(s, MAX_DATA); bool found; u64 start, dt; u64 i; printf("%s\n", __FUNCTION__); for (i = 0; i < NUM_KEYS; i++) { a = MkKey(twister_random(), twister_random()); key[i] = a; RandSlice(&s); Put(&t, a, s); } start = nsecs(); for (i = 0; i < NUM_KEYS; i++) { a = key[i]; Get(&t, a, &s, &found); if (!found) fatal("didn't find %lld.%lld", a.key[0], a.key[1]); } dt = nsecs() - start; printf("%lld nsecs %g nsecs/op\n", dt, (double)dt/(double)i); }
void *rgb (void *arg) { arg_s *a = arg; u64 start, finish; unint i; rgb_lock(a->name, &Red); start = nsecs(); for (i = Loops; i; i--) { #if (!DEBUG && !MUTEX && !SPIN && !TSPIN) donothing(); #endif rgb_lock(a->name, &Green); rgb_unlock(a->name, &Red); rgb_lock(a->name, &Blue); rgb_unlock(a->name, &Green); rgb_lock(a->name, &Red); rgb_unlock(a->name, &Blue); } rgb_unlock(a->name, &Red); finish = nsecs(); printf("%s %g nsecs per lock-unlock pair\n", a->name, ((double)(finish - start))/(3 * Loops)); return NULL; }
void memcpy_loop (int j, u8 *a, u8 *b, int n, void *function) { memcpy_f f = function; u64 start; u64 finish; int i; start = nsecs(); for (i = Option.iterations; i > 0; i--) { f(a, b, n); if (bidirectional) f(b, a, n); } finish = nsecs(); if (bidirectional) { printf("%d. %g %s/sec\n", j, 2.0 * meg.scale * (n * (u64)Option.iterations) / (double)(finish - start), meg.units); } else { printf("%d. %g %s/sec\n", j, meg.scale * (n * (u64)Option.iterations) / (double)(finish - start), meg.units); } }
void *producer (void *arg) { u64 start, finish; unint wait = 0; unint i; ++P; while (P > C) { sleep(0); } printf("Producer\n"); start = nsecs(); for (i = 0; i < Loops; i++, P++) { while (P > C) { #if SLEEP sleep(0); #elif DONOTHING donothing(); #endif ++wait; } } finish = nsecs(); printf("producer %g nsecs per increment and %g waits\n", ((double)(finish - start)) / Loops, (double)wait / Loops); return NULL; }
void BzTest16(void) { enum { NUM_KEYS = ONE_MILLION }; static Key key[NUM_KEYS]; VAR_LUMP(v, MAX_DATA); Bz t; Key a; bool found; u64 start, dt; u64 i; printf("%s\n", __FUNCTION__); RandLump(v); init_twister(17); BzInit(&t, KEY_LEN); for (i = 0; i < NUM_KEYS; i++) { a = RandKey(); key[i] = a; BzPut(&t, a.s, v); } start = nsecs(); for (i = 0; i < NUM_KEYS; i++) { a = key[i]; BzGet(&t, a.s, &found); if (!found) fatal("didn't find %s", a.s); } dt = nsecs() - start; printf("%llu nsecs %g nsecs/get op\n", dt, (double)dt/(double)i); }
int main(int argc, char ** argv) { unsigned int i, k, timeSumEmpty = 0, timeSumFull = 0; //int arr1[SIZE]; //int arr2[SIZE]; // int * arr1 = malloc(SIZE * sizeof(int)); //int * arr2 = malloc(SIZE * sizeof(int)); nsecs(); for (i = 0; i < TESTS; ++i) { for (k = 0; k < SIZE; ++k){} // printf("Pusta: %ld ", msecs()); timeSumEmpty += nsecs(); for (k = 0; k < SIZE; ++k) { //arr1[k] = k; //arr2[k] = SIZE - k; *(arr1 + k) = k; *(arr2 + k) = SIZE - k; } timeSumFull += nsecs(); //printf("Pelna: %ld\n", msecs()); } printf("Przebiegow %d po %d\n Sr. czas pustej: %10.4lf pelnej %10.4lf\n", TESTS, SIZE, (double)timeSumEmpty/(TESTS*1000000), (double)timeSumFull/(TESTS*1000000)); //free(arr1); //free(arr2); return 0; }
void *rgb (void *arg) { arg_s *a = arg; u64 start, finish; unint red = a->id; unint green = a->id + 1; unint i; rgb_lock(a->name, &Lock[red]); dec_count(); rgb_lock("start", &StartLock); rgb_unlock("start", &StartLock); start = nsecs(); for (i = Loops; i; i--) { #if (!DEBUG && !MUTEX && !SPIN && !TSPIN) donothing(); #endif rgb_lock(a->name, &Lock[green]); rgb_unlock(a->name, &Lock[red]); if (++red == Num_locks) red = 0; if (++green == Num_locks) green = 0; } rgb_unlock(a->name, &Lock[red]); finish = nsecs(); printf("%s %g nsecs per lock-unlock pair\n", a->name, ((double)(finish - start))/Loops); return NULL; }
void BaTest16(void) { enum { NUM_KEYS = ONE_MILLION }; static u64 key[NUM_KEYS]; Ba t; u64 a; bool found; u64 start, dt; u64 i; printf("%s\n", __FUNCTION__); init_twister(17); BaInit(&t); for (i = 0; i < NUM_KEYS; i++) { a = twister_random(); key[i] = a; BaPut(&t, a); } start = nsecs(); for (i = 0; i < NUM_KEYS; i++) { a = key[i]; BaGet(&t, a, &found); if (!found) fatal("didn't find %llu", a); } dt = nsecs() - start; printf("%llu nsecs %g nsecs/get op\n", dt, (double)dt/(double)i); }
void BcTest14(void) { enum { NUM_RECS = 200, NUM_ITER = 100 * ONE_THOUSAND }; VAR_LUMP(v, MAX_DATA); Bc *t = emalloc(sizeof(*t) * NUM_ITER); u64 start, dt; u64 i, j; printf("%s\n", __FUNCTION__); init_twister(17); RandLump(v); start = nsecs(); for (j = 0; j < NUM_ITER; j++) { BcInit(&t[j], KEY_LEN); for (i = 0; i < NUM_RECS; i++) { BcPut(&t[j], RandKey().s, v); } } dt = nsecs() - start; printf("%llu nsecs %g nsecs/op\n", dt, (double)dt/(double)(i * j)); BcReport(__FUNCTION__, BcDoAudit(&t[0])); for (j = 0; j < NUM_ITER; j++) { BcDoAudit(&t[j]); BcFree(&t[j]); } }
void test_jsw_level (int n, int level) { struct jsw_tree tree = { 0 }; u64 key; s64 count = 0; int i; int rc; u64 start, finish, total; k_seed(1); k_init(); start = nsecs(); for (i = 0; i < n; i++) { if (k_should_delete(count, level)) { key = k_delete_rand(); rc = jsw_remove(&tree, key); if (!rc) fatal("jswremove key=%lld", key); --count; } else { key = k_rand_key(); k_add(key); rc = jsw_insert(&tree, key); if (!rc) fatal("jswinsert key=%lld", key); ++count; } } finish = nsecs(); total = finish - start; printf("%lld nsecs %g nsecs/op\n", total, (double)total/(double)n); }
static void Test15(void) { Tree t = { NULL }; Key a; VAR_SLICE(s, MAX_DATA); u64 start, dt; u64 i; printf("%s\n", __FUNCTION__); for (i = 0; i < LAG; i++) { a = MkKey(i, 0); RandSlice(&s); Put(&t, a, s); PutRing(i); } start = nsecs(); for (; i < TRYS; i++) { a = MkKey(i, 0); RandSlice(&s); Put(&t, a, s); PutRing(i); a = MkKey(GetRandRing(), 0); Delete(&t, a); } dt = nsecs() - start; printf("%lld nsecs %g nsecs/op\n", dt, (double)dt/(double)TRYS); Dump(WHERE, &t); }
void BaTest15(void) { enum { NUM_RECS = 200, NUM_ITER = 100 * ONE_THOUSAND }; Ba t[NUM_ITER]; u64 key; bool found; u64 start, dt; u64 i, j; printf("%s\n", __FUNCTION__); init_twister(17); start = nsecs(); for (j = 0; j < NUM_ITER; j++) { BaInit(&t[j]); for (i = 0; i < NUM_RECS; i++) { BaPut(&t[j], twister_random()); } } dt = nsecs() - start; printf("put %llu nsecs %g nsecs/op\n", dt, (double)dt/(double)(i * j)); init_twister(17); start = nsecs(); for (j = 0; j < NUM_ITER; j++) { for (i = 0; i < NUM_RECS; i++) { BaGet(&t[j], twister_random(), &found); if (!found) { fatal("Didn't find key for iter %llu rec %llu", j, i); } } } dt = nsecs() - start; printf("get %llu nsecs %g nsecs/op\n", dt, (double)dt/(double)(i * j)); key = 0; start = nsecs(); for (j = 0; j < NUM_ITER; j++) { for (i = 0; i < NUM_RECS; i++) { bool isEof; BaNext(&t[j], key, &key, &isEof); if (!found) { fatal("Didn't find key for iter %llu rec %llu", j, i); } } } dt = nsecs() - start; printf("next %llu nsecs %g nsecs/op\n", dt, (double)dt/(double)(i * j)); init_twister(17); start = nsecs(); for (j = 0; j < NUM_ITER; j++) { for (i = 0; i < NUM_RECS; i++) { twister_random(); } } dt = nsecs() - start; printf("overhead %llu nsecs %g nsecs/op\n", dt, (double)dt/(double)(i * j)); }
void TestPrTime(void) { init_twister(nsecs()); for (int i = 0; i < 50; i++) { u64 t = twister_urand(1ull<<i); printf("%3d. %16lld %s\n", i, t, TimeStringer(t).s); } }
void memsum_loop (int j, u8 *a, u8 *b, int n, void *function) { memsum_f f = function; u64 start; u64 finish; int i; start = nsecs(); for (i = Option.iterations; i > 0; i--) { f(a, n); } finish = nsecs(); printf("%d. %g %s/sec\n", j, meg.scale * (n * (u64)Option.iterations) / (double)(finish - start), meg.units); }
static void Test13(void) { Tree t = { NULL }; Key a; VAR_SLICE(s, MAX_DATA); u64 start, dt; u64 i; printf("%s\n", __FUNCTION__); RandSlice(&s); start = nsecs(); for (i = 0; i < 1000000; i++) { a = MkKey(twister_random(), twister_random()); Put(&t, a, s); } dt = nsecs() - start; printf("%lld nsecs %g nsecs/op\n", dt, (double)dt/(double)i); }
void BaTest13(void) { enum { NUM_RECS = 10 * ONE_MILLION / 10 }; Ba t; u64 start, dt; u64 i; printf("%s\n", __FUNCTION__); init_twister(17); BaInit(&t); start = nsecs(); for (i = 0; i < NUM_RECS; i++) { BaPut(&t, twister_random()); } dt = nsecs() - start; printf("%llu nsecs %g nsecs/op\n", dt, (double)dt/(double)i); BaReportAudit(__FUNCTION__, BaDoAudit(&t)); }
void BbTest17(void) { enum { NUM_KEYS = ONE_MILLION }; static Key key[NUM_KEYS]; VAR_LUMP(v, MAX_DATA); Bb t; BB_ITER(iter, sizeof(Key)); bool found; u64 start, dt; u64 i; printf("%s\n", __FUNCTION__); RandLump(v); init_twister(17); BbInit(&t, KEY_LEN); for (i = 0; i < NUM_KEYS; i++) { key[i] = RandKey(); } start = nsecs(); for (i = 0; i < NUM_KEYS; i++) { BbPut(&t, key[i].s, v); } dt = nsecs() - start; printf("BbPut: %llu nsecs %g nsecs/put op\n", dt, (double)dt/(double)i); start = nsecs(); for (i = 0; i < NUM_KEYS; i++) { BbGet(&t, key[i].s, &found); if (!found) fatal("didn't find %s", key[i].s); } dt = nsecs() - start; printf("BbGet: %llu nsecs %g nsecs/get op\n", dt, (double)dt/(double)i); //BbIter *iter = BbIterNew(&t); BbIterInit(iter, &t); start = nsecs(); for (i = 0; i < NUM_KEYS; i++) { if (!BbIterNext(iter)) fatal("didn't find %s", iter->key); } dt = nsecs() - start; //BbIterFree(iter); printf("BbIter: %llu nsecs %g nsecs/get op\n", dt, (double)dt/(double)i); start = nsecs(); for (i = 0; i < NUM_KEYS; i++) { BbDelete(&t, key[i].s); } dt = nsecs() - start; printf("BbDelete: %llu nsecs %g nsecs/delete op\n", dt, (double)dt/(double)i); BbFree(&t); }
void BcTest18(void) { enum { NUM_KEYS = 1000 * ONE_THOUSAND }; static BigKey key[NUM_KEYS]; BigKey startKey = {{ 0 }}; VAR_LUMP(v, MAX_DATA); Bc t; BB_ITER(iter, sizeof(key[0])); bool found; u64 start, dt; u64 i; printf("%s\n", __FUNCTION__); RandLump(v); init_twister(17); BcInit(&t, sizeof(key[0])); for (i = 0; i < NUM_KEYS; i++) { key[i] = RandBigKey(); } start = nsecs(); for (i = 0; i < NUM_KEYS; i++) { BcPut(&t, key[i].s, v); } dt = nsecs() - start; printf("BcPut: %llu nsecs %g nsecs/put op\n", dt, (double)dt/(double)i); start = nsecs(); for (i = 0; i < NUM_KEYS; i++) { BcGet(&t, key[i].s, &found); if (!found) fatal("didn't find %s", key[i].s); } dt = nsecs() - start; printf("BcGet: %llu nsecs %g nsecs/get op\n", dt, (double)dt/(double)i); BcIterInit(iter, &t, startKey.s); start = nsecs(); for (i = 0; i < NUM_KEYS; i++) { if (!BcIterNext(iter)) fatal("didn't find %u. %s", i, iter->key); } dt = nsecs() - start; printf("BcIter: %llu nsecs %g nsecs/get op\n", dt, (double)dt/(double)i); start = nsecs(); for (i = 0; i < NUM_KEYS; i++) { BcDelete(&t, key[i].s); } dt = nsecs() - start; printf("BcDelete: %llu nsecs %g nsecs/delete op\n", dt, (double)dt/(double)i); BcFree(&t); }
void RecordTime(int id, u64 start) { u64 dt = nsecs() - start; Timer *t; aver(0 < id && id < MAX_TIMERS); t = &Timers[id]; if (dt < t->min) t->min = dt; if (t->max < dt) t->max = dt; t->total += dt; t->n++; }
void BzTest13(void) { enum { NUM_RECS = 10 * ONE_MILLION / 10 }; VAR_LUMP(v, MAX_DATA); Bz t; u64 start, dt; u64 i; printf("%s\n", __FUNCTION__); init_twister(17); BzInit(&t, KEY_LEN); RandLump(v); start = nsecs(); for (i = 0; i < NUM_RECS; i++) { BzPut(&t, RandKey().s, v); } dt = nsecs() - start; printf("%llu nsecs %g nsecs/op\n", dt, (double)dt/(double)i); BzReportAudit(__FUNCTION__, BzDoAudit(&t)); }
void BaTest14(void) { enum { NUM_RECS = 200, NUM_ITER = 100 * ONE_THOUSAND }; Ba t; u64 start, dt; u64 i, j; printf("%s\n", __FUNCTION__); init_twister(17); start = nsecs(); for (j = 0; j < NUM_ITER; j++) { BaInit(&t); for (i = 0; i < NUM_RECS; i++) { BaPut(&t, twister_random()); } } dt = nsecs() - start; printf("%llu nsecs %g nsecs/op\n", dt, (double)dt/(double)(i * j)); BaReportAudit(__FUNCTION__, BaDoAudit(&t)); }
int main (int argc, char *argv[]) { char *dir = "."; tick_t start; tick_t finish; tick_t total; if (argc > 1) dir = argv[1]; NumFiles = 0; start = nsecs(); nftw_walk_tree(dir); finish = nsecs(); total = finish - start; printf("%lld nsecs %d\n", total, NumFiles); NumFiles = 0; start = nsecs(); walk_dir(dir, donothing, NULL, 0); finish = nsecs(); total = finish - start; printf("%lld nsecs %d\n", total, NumFiles); NumFiles = 0; start = nsecs(); walk_tree(dir, prfile, NULL); finish = nsecs(); total = finish - start; printf("%lld nsecs %d\n", total, NumFiles); return 0; }
void *consumer (void *arg) { u64 start, finish; unint wait = 0; unint i; printf("Consumer\n"); start = nsecs(); for (i = 0; i < Loops; i++, C++) { while (C >= P) { #if SLEEP sleep(0); #elif DONOTHING donothing(); #endif ++wait; } } finish = nsecs(); printf("consumer %g nsecs per increment and %g waits\n", ((double)(finish - start)) / Loops, (double)wait / Loops); return NULL; }
void BzTest14(void) { enum { NUM_RECS = 200, NUM_ITER = 100 * ONE_THOUSAND }; VAR_LUMP(v, MAX_DATA); Bz t; u64 start, dt; u64 i, j; printf("%s\n", __FUNCTION__); init_twister(17); RandLump(v); start = nsecs(); for (j = 0; j < NUM_ITER; j++) { BzInit(&t, KEY_LEN); for (i = 0; i < NUM_RECS; i++) { BzPut(&t, RandKey().s, v); } } dt = nsecs() - start; printf("%llu nsecs %g nsecs/op\n", dt, (double)dt/(double)(i * j)); BzReportAudit(__FUNCTION__, BzDoAudit(&t)); }
std::ostream& gu::datetime::operator<<(std::ostream& os, const Period& p) { os << "P"; int64_t nsecs(p.get_nsecs()); if (nsecs/Year > 0) { os << (nsecs/Year) << "Y"; nsecs %= Year; } if (nsecs/Month > 0) { os << (nsecs/Month) << "M"; nsecs %= Month; } if (nsecs/Day > 0) { os << (nsecs/Day) << "D"; nsecs %= Day; } if (nsecs > 0) { os << "T"; } if (nsecs/Hour > 0) { os << (nsecs/Hour) << "H"; nsecs %= Hour; } if (nsecs/Min > 0) { os << (nsecs/Min) << "M"; nsecs %= Min; } if (double(nsecs)/Sec >= 1.e-9) { os << (double(nsecs)/Sec) << "S"; } return os; }
/* init_test creates a scratch directory in the specified * test directory. * * It also creates some test files to help in testing. Because, * we want to test >4 Gigfiles but it takes time to create a file * that big, we create it here and allow its size to be set by * the user -- use a small size when developing the tests. */ void init_test (char *dir) { char *suffix; if (Local_option.seed_rand) srandom(nsecs()); CheckRoot = (geteuid() == 0); chdir(dir); chdirErr(ENOTDIR, "/etc/passwd"); suffix = RndName(); Scratch = Catstr("scratch_", suffix, 0); free(suffix); mkdir(Scratch, 0777); chdir(Scratch); CrFile(BigFile, Local_option.size_big_file); CrFile(EmptyFile, 0); CrFile(OneFile, 1); }
/*! Get tickval as struct timespec \return result */ struct timespec as_ts() const { const timespec ts = { secs(), static_cast<long>(nsecs()) }; return ts; }
int main (int argc, char *argv[]) { msg_s msg; ki_t key; int c; int rc; char *send_color; char *recv_color; unint i; unint n = 1000; u64 start = 0; u64 finish; setprogname(argv[0]); while ((c = getopt(argc, argv, "p?")) != -1) { switch (c) { case 'p': prompt_on(); break; default: usage(); break; } } if (argc < optind+2) usage(); send_color = argv[optind]; recv_color = argv[optind+1]; if (argc > optind+2) { n = strtoll(argv[optind+2], NULL, 0); } prompt("start"); if (init_msg_tau(send_color)) { exit(2); } prompt("sw_register"); sw_register(send_color); prompt("create_gate_tau"); key = make_gate(0, REQUEST); prompt("sw_post"); rc = sw_post(send_color, key); if (rc) failure("sw_post", rc); prompt("sw_any"); rc = sw_any(recv_color, &key); if (rc) failure("sw_any", rc); for (i = 0; i < n; i++) { if (i == 2) start = nsecs(); prompt("send_tau"); rc = send_tau(key, &msg); if (rc) failure("send_tau", rc); prompt("receive_tau"); rc = receive_tau( &msg); if (rc) failure("receive", rc); } finish = nsecs(); printf("%s %g nsecs per send/receive\n", send_color, ((double)(finish - start))/(n-2)); return 0; }
void BzTest15(void) { enum { NUM_RECS = 200, NUM_ITER = 100 * ONE_THOUSAND }; VAR_LUMP(v, MAX_DATA); Bz t[NUM_ITER]; bool found; u64 start, dt; u64 i, j; printf("%s\n", __FUNCTION__); RandLump(v); init_twister(17); start = nsecs(); for (j = 0; j < NUM_ITER; j++) { BzInit(&t[j], KEY_LEN); for (i = 0; i < NUM_RECS; i++) { BzPut(&t[j], RandKey().s, v); } } dt = nsecs() - start; printf("put %llu nsecs %g nsecs/op\n", dt, (double)dt/(double)(i * j)); init_twister(17); start = nsecs(); for (j = 0; j < NUM_ITER; j++) { for (i = 0; i < NUM_RECS; i++) { BzGet(&t[j], RandKey().s, &found); if (!found) { fatal("Didn't find key for iter %llu rec %llu", j, i); } } } dt = nsecs() - start; printf("get %llu nsecs %g nsecs/op\n", dt, (double)dt/(double)(i * j)); start = nsecs(); for (j = 0; j < NUM_ITER; j++) { for (i = 0; i < NUM_RECS; i++) { Key key; bool isEof; BzNext(&t[j], RandKey().s, key.s, &isEof); if (!found) { fatal("Didn't find key for iter %llu rec %llu", j, i); } } } dt = nsecs() - start; printf("next %llu nsecs %g nsecs/op\n", dt, (double)dt/(double)(i * j)); init_twister(17); start = nsecs(); for (j = 0; j < NUM_ITER; j++) { for (i = 0; i < NUM_RECS; i++) { RandKey(); } } dt = nsecs() - start; printf("overhead %llu nsecs %g nsecs/op\n", dt, (double)dt/(double)(i * j)); }