// compile: gcc -o test test.c upstream_blake3/c/blake3.c upstream_blake3/c/blake3_dispatch.c upstream_blake3/c/blake3_portable.c -DBLAKE3_NO_SSE2 -DBLAKE3_NO_AVX2 -DBLAKE3_NO_AVX512 -DBLAKE3_NO_NEON -DBLAKE3_NO_SSE41 // gcc -o test test.c upstream_blake3/c/blake3.c upstream_blake3/c/blake3_dispatch.c upstream_blake3/c/blake3_portable.c upstream_blake3/c/blake3_sse2_x86-64_unix.S upstream_blake3/c/blake3_sse41_x86-64_unix.S upstream_blake3/c/blake3_avx2_x86-64_unix.S upstream_blake3/c/blake3_avx512_x86-64_unix.S #include #include #include #include "upstream_blake3/c/blake3.h" #include #include #include #include int64_t nanoseconds() { struct timespec ts; clock_gettime(CLOCK_REALTIME, &ts); return (int64_t)ts.tv_sec * 1000000000 + (int64_t)ts.tv_nsec; } int main(int argc, char *argv[]) { if (argc != 2) { printf("Usage: %s \n", argv[0]); return 1; } int iterations = atoi(argv[1]); char teststr[16 * 1024] = "Hello World!"; // 16kb is an important size: it's the size of the TLS record buffer. int64_t best = INT64_MAX; for (int i = 0; i < iterations; i++) { int64_t start = nanoseconds(); blake3_hasher hasher; blake3_hasher_init(&hasher); blake3_hasher_update(&hasher, teststr, sizeof(teststr)); uint8_t output[BLAKE3_OUT_LEN]; blake3_hasher_finalize(&hasher, output, BLAKE3_OUT_LEN); int64_t end = nanoseconds(); int64_t elapsed = end - start; if (elapsed < best) { best = elapsed; } } //printf("Best time: %ld nanoseconds\n", best); printf("%ld\n", best); printf("\n"); return 0; }