interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / om / sha256 / om2-evidence / s4 / measure / bench.c

52 lines · 2443 bytes Raw Blame History
1/* Throwaway measurement driver (not delivered code). Links one arm's libomega_gpu.a and times
2 * sha256_hash / sha256_init+update+final per size. One process per arm per round. */
3#include <stdint.h>
4#include <stdio.h>
5#include <stdlib.h>
6#include <string.h>
7#include <time.h>
8#include "sha256.h"
9
10static double now_ns(void) { struct timespec t; clock_gettime(CLOCK_MONOTONIC, &t); return (double)t.tv_sec*1e9 + (double)t.tv_nsec; }
11static int cmp(const void*a,const void*b){ double x=*(const double*)a, y=*(const double*)b; return x<y?-1:(x>y); }
12
13static const size_t sizes[] = {0,1,31,32,55,56,63,64,65,127,128,1024,4096,65536,1048576,16777216};
14static const size_t chunk[] = {1,7,64,4096};
15
16int main(int argc, char** argv) {
17 int reps = argc > 1 ? atoi(argv[1]) : 31;
18 static uint8_t *big = NULL;
19 size_t bigcap = 1u<<24;
20 big = malloc(bigcap);
21 for (size_t i = 0; i < bigcap; i++) big[i] = (uint8_t)(i*31u + 7u);
22 uint8_t d[SHA256_DIGEST_SIZE];
23 int bad = 0;
24 for (unsigned s = 0; s < sizeof sizes/sizeof *sizes; s++) {
25 size_t n = sizes[s];
26 for (int w = 0; w < 3; w++) (void)sha256_hash(big, n, d);
27 double *v = malloc((size_t)reps * sizeof(double));
28 for (int r = 0; r < reps; r++) { double t0 = now_ns(); (void)sha256_hash(big, n, d); v[r] = now_ns() - t0; }
29 qsort(v, (size_t)reps, sizeof(double), cmp);
30 printf("hash %zu %.1f %.1f %.1f %.1f %.1f %02x\n", n, v[0], v[reps/2], v[(reps*9)/10], v[reps-1],
31 v[reps/2]/ (n ? (double)n : 1.0), d[0]);
32 free(v);
33 }
34 for (unsigned c = 0; c < sizeof chunk/sizeof *chunk; c++) {
35 size_t cs = chunk[c], total = 1u<<20;
36 sha256_ctx ctx;
37 for (int w = 0; w < 3; w++) { sha256_init(&ctx); for (size_t o = 0; o < total; o += cs) sha256_update(&ctx, big+o, cs); sha256_final(&ctx, d); }
38 double *v = malloc((size_t)reps * sizeof(double));
39 for (int r = 0; r < reps; r++) {
40 double t0 = now_ns();
41 sha256_init(&ctx);
42 for (size_t o = 0; o < total; o += cs) sha256_update(&ctx, big+o, cs);
43 sha256_final(&ctx, d);
44 v[r] = now_ns() - t0;
45 }
46 qsort(v, (size_t)reps, sizeof(double), cmp);
47 printf("stream %zu %zu %.1f %.1f %.1f %.1f %.1f %02x\n", cs, total, v[0], v[reps/2], v[(reps*9)/10], v[reps-1],
48 (total/1048576.0)/(v[reps/2]/1e9), d[0]);
49 free(v);
50 }
51 return bad;
52}