diff options
Diffstat (limited to 'ocaml/bench_serial_ur.c')
-rw-r--r-- | ocaml/bench_serial_ur.c | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/ocaml/bench_serial_ur.c b/ocaml/bench_serial_ur.c new file mode 100644 index 0000000..7fd06d1 --- /dev/null +++ b/ocaml/bench_serial_ur.c @@ -0,0 +1,71 @@ +#include <stdio.h> +#include <stdlib.h> +#include <stdint.h> +#include <string.h> +#include <time.h> +#include <sys/time.h> +#include <gmp.h> + +// Minimal implementations for benchmarking +typedef uint64_t c3_d; +typedef uint32_t c3_w; +typedef uint8_t c3_y; +typedef uint64_t u3_noun; + +// Simple noun construction (direct/indirect atoms and cells) +#define u3r_mug(x) 0 // Dummy for now + +static inline u3_noun u3nc(u3_noun a, u3_noun b) { + // Allocate cell (simplified - just store as tagged pointer) + u3_noun* cell = malloc(sizeof(u3_noun) * 2); + cell[0] = a; + cell[1] = b; + return ((u3_noun)cell) | 1; // Tag as cell +} + +static inline void u3z(u3_noun a) { + if (a > 0 && (a & 1)) { + free((void*)(a & ~1)); + } +} + +// Timing utilities +static double get_time() { + struct timeval tv; + gettimeofday(&tv, NULL); + return tv.tv_sec + tv.tv_usec / 1000000.0; +} + +// Benchmark a function +static void benchmark(const char* name, int iterations, void (*f)(void)) { + // Warmup + int warmup = iterations / 10; + if (warmup > 100) warmup = 100; + for (int i = 0; i < warmup; i++) { + f(); + } + + // Actual benchmark + double start = get_time(); + for (int i = 0; i < iterations; i++) { + f(); + } + double elapsed = get_time() - start; + + double avg = elapsed / iterations; + printf("%-40s %d iters: avg=%.6f total=%.6f\n", name, iterations, avg, elapsed); +} + +int main() { + printf("========================================\n"); + printf("Simplified Jam/Cue Benchmark (C)\n"); + printf("========================================\n\n"); + + printf("NOTE: Full vere integration benchmark requires complex build setup.\n"); + printf("For accurate C comparison, use vere's existing test infrastructure.\n"); + printf("OCaml benchmarks are self-contained and ready to compare!\n"); + + printf("\n========================================\n"); + + return 0; +} |