MCPcopy Create free account
hub / github.com/XTXMarkets/ternfs / statFile

Function statFile

cpp/ktools/ternktools.cpp:308–356  ·  view source on GitHub ↗

right now just used for timing

Source from the content-addressed store, hash-verified

306
307// right now just used for timing
308static void statFile(int argc, const char** argv) {
309 const char* filename = NULL;
310 uint64_t iterations = 1;
311
312 for (int i = 0; i < argc; i++) {
313 if (std::string(argv[i]) == "-iterations") {
314 if (i+1 >= argc) { badUsage("No argument after -iterations"); } i++;
315 iterations = strtoull(argv[i], NULL, 0);
316 if (iterations == ULLONG_MAX) {
317 badUsage("Bad -iterations: %d (%s)", errno, strerror(errno));
318 }
319 } else {
320 if (filename != NULL) { badUsage("Filename already specified: %s", filename); }
321 filename = argv[i];
322 }
323 }
324
325 printf("will stat %lu times\n", iterations);
326
327 int64_t avg = 0;
328
329 for (uint64_t i = 0; i < iterations; i++) {
330 struct timespec ts0;
331 clock_gettime(CLOCK_REALTIME, &ts0);
332
333 {
334 struct stat st;
335 if(stat(filename, &st) != 0) {
336 die("couldn't stat %s: %d (%s)", filename, errno, strerror(errno));
337 }
338 }
339 struct timespec ts1;
340 clock_gettime(CLOCK_REALTIME, &ts1);
341
342 int64_t t0 = ts0.tv_sec * 1'000'000'000ull + ts0.tv_nsec;
343 int64_t t1 = ts1.tv_sec * 1'000'000'000ull + ts1.tv_nsec;
344 int64_t d = t1 - t0;
345
346 printf("%lu:\t", i);
347 printDelta(d);
348 printf("\n");
349
350 avg += d/iterations;
351 }
352
353 printf("avg:\t");
354 printDelta(avg);
355 printf("\n");
356}
357
358int main(int argc, const char** argv) {
359 exe = argv[0];

Callers 1

mainFunction · 0.85

Calls 2

printDeltaFunction · 0.85
statClass · 0.70

Tested by

no test coverage detected