#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <time.h>
#include <unistd.h>
#include <keks/dec.h>
{
bool doEncode = false;
bool noTotals = false;
+ bool onlyTotals = false;
ptrdiff_t itemsInitialLen = 2048;
NoColour = getenv("NO_COLOR") != NULL;
struct option longopts[] = {
{"do-encode", no_argument, NULL, 'b'},
{"no-offsets", no_argument, NULL, 'c'},
{"no-totals", no_argument, NULL, 'd'},
+ {"only-totals", no_argument, NULL, 'e'},
{"items-initial-len", required_argument, NULL, 'f'},
{NULL, 0, NULL, 0}};
int ch = 0;
case 'd': // no-totals
noTotals = true;
break;
+ case 'e': // only-totals
+ onlyTotals = true;
+ break;
case 'f': { // items-initial-len
errno = 0;
long tmp = strtol(optarg, NULL, 10);
items.offsets = NULL;
}
size_t off = 0;
+ struct timespec started;
+ struct timespec finished;
+ errno = 0;
+ if (clock_gettime(CLOCK_MONOTONIC_PRECISE, &started) != 0) {
+ fprintf(stderr, "clock_gettime(started): %s\n", strerror(errno));
+ exit(EXIT_FAILURE);
+ }
err = KEKSItemsParse(&items, &off, buf, len);
- if (err != KEKSErrNo) {
- fprintf(stderr, "err: %s\n", KEKSErr2Str(err));
- return EXIT_FAILURE;
+ errno = 0;
+ if (clock_gettime(CLOCK_MONOTONIC_PRECISE, &finished) != 0) {
+ fprintf(stderr, "clock_gettime(finished): %s\n", strerror(errno));
+ exit(EXIT_FAILURE);
}
- err = printer(&items, 0, 0, false, 0, NULL);
if (err != KEKSErrNo) {
fprintf(stderr, "err: %s\n", KEKSErr2Str(err));
return EXIT_FAILURE;
}
+ if (!onlyTotals) {
+ err = printer(&items, 0, 0, false, 0, NULL);
+ if (err != KEKSErrNo) {
+ fprintf(stderr, "err: %s\n", KEKSErr2Str(err));
+ return EXIT_FAILURE;
+ }
+ }
if (!noTotals) {
printf(
- "items: %zu size: %zu\n",
+ "items: %zu size: %zu time: %zuns\n",
items.len,
- items.len * (sizeof(struct KEKSItem) + (NoOffsets ? 0 : sizeof(size_t))));
+ items.len * (sizeof(struct KEKSItem) + (NoOffsets ? 0 : sizeof(size_t))),
+ 1000000000 * (finished.tv_sec - started.tv_sec) + finished.tv_nsec -
+ started.tv_nsec);
}
if (off < len) {
char *hex = HexEnc(buf + off, len - off);