diff options
author | polwex <polwex@sortug.com> | 2025-10-07 03:08:57 +0700 |
---|---|---|
committer | polwex <polwex@sortug.com> | 2025-10-07 03:08:57 +0700 |
commit | a3170453e08079369da031377c45600ee22ab53a (patch) | |
tree | 22a90cdf95202d1fe760acf71d85716b1ce3082a /ocaml/test/test_ivory_parallel.ml | |
parent | 64611d312280dd5d63d498ded09ae4e9a6eaf34c (diff) |
nock diversity
Diffstat (limited to 'ocaml/test/test_ivory_parallel.ml')
-rw-r--r-- | ocaml/test/test_ivory_parallel.ml | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/ocaml/test/test_ivory_parallel.ml b/ocaml/test/test_ivory_parallel.ml new file mode 100644 index 0000000..44b373f --- /dev/null +++ b/ocaml/test/test_ivory_parallel.ml @@ -0,0 +1,106 @@ +(** Test ivory pill lifecycle with all three Nock implementations in parallel **) + +open Nock_lib + +let time_it name f = + Printf.printf " [%s] Starting...\n%!" name; + let start = Unix.gettimeofday () in + let result = f () in + let elapsed = Unix.gettimeofday () -. start in + Printf.printf " [%s] ✓ Complete in %.4fs\n%!" name elapsed; + (name, elapsed, result) + +let () = + Printf.printf "\n╔═══════════════════════════════════════════════════════╗\n"; + Printf.printf "║ Parallel Ivory Pill Lifecycle Test ║\n"; + Printf.printf "╚═══════════════════════════════════════════════════════╝\n\n"; + + Printf.printf "[1] Loading ivory.pill...\n"; + let ic = open_in_bin "ivory.pill" in + let len = in_channel_length ic in + let bytes = Bytes.create len in + really_input ic bytes 0 len; + close_in ic; + Printf.printf " Size: %d bytes\n" len; + + Printf.printf "[2] Cuing ivory pill...\n"; + let pill = Serial.cue bytes in + Printf.printf " ✓ Cued\n"; + + match pill with + | Noun.Cell { h = _tag; t = core; _ } -> + Printf.printf "[3] Building lifecycle formula...\n"; + let formula = Noun.cell + (Noun.atom 2) + (Noun.cell + (Noun.cell (Noun.atom 0) (Noun.atom 3)) + (Noun.cell (Noun.atom 0) (Noun.atom 2))) in + Printf.printf " Formula: [2 [0 3] [0 2]]\n"; + + Printf.printf "\n[4] Running lifecycle with all three implementations:\n\n"; + + (* Spawn domains for parallel execution *) + let domain1 = Domain.spawn (fun () -> + time_it "nock.ml" (fun () -> + Nock.nock_on core formula) + ) in + + let domain2 = Domain.spawn (fun () -> + time_it "nock_iter.ml" (fun () -> + Nock_iter.nock_on core formula) + ) in + + let domain3 = Domain.spawn (fun () -> + time_it "nock_tail.ml" (fun () -> + Nock_tail.nock_on core formula) + ) in + + (* Wait for all to complete *) + Printf.printf "\n[5] Joining domain1...%!\n"; + let (name1, time1, result1) = Domain.join domain1 in + Printf.printf "[5] Joining domain2...%!\n"; + let (name2, time2, result2) = Domain.join domain2 in + Printf.printf "[5] Joining domain3...%!\n"; + let (name3, time3, result3) = Domain.join domain3 in + + Printf.printf "\n[6] Computing mugs (this may take a moment)...\n%!"; + Printf.printf " Computing mug for %s...%!" name1; + let mug1 = Noun.mug result1 in + Printf.printf " 0x%08lx\n%!" mug1; + + Printf.printf " Computing mug for %s...%!" name2; + let mug2 = Noun.mug result2 in + Printf.printf " 0x%08lx\n%!" mug2; + + Printf.printf " Computing mug for %s...%!" name3; + let mug3 = Noun.mug result3 in + Printf.printf " 0x%08lx\n%!" mug3; + + Printf.printf "\n[7] Results:\n"; + Printf.printf " %s: 0x%08lx (%.4fs)\n" name1 mug1 time1; + Printf.printf " %s: 0x%08lx (%.4fs)\n" name2 mug2 time2; + Printf.printf " %s: 0x%08lx (%.4fs)\n" name3 mug3 time3; + + Printf.printf "\n[8] Verification:\n"; + if mug1 = mug2 && mug2 = mug3 then + Printf.printf " ✓ All three mugs match - kernels are identical!\n" + else begin + Printf.printf " ✗ MISMATCH!\n"; + if mug1 <> mug2 then + Printf.printf " nock.ml ≠ nock_iter.ml\n"; + if mug2 <> mug3 then + Printf.printf " nock_iter.ml ≠ nock_tail.ml\n"; + if mug1 <> mug3 then + Printf.printf " nock.ml ≠ nock_tail.ml\n" + end; + + Printf.printf "\n╔═══════════════════════════════════════════════════════╗\n"; + Printf.printf "║ Summary: ║\n"; + Printf.printf "║ Fastest: %-44s║\n" + (if time1 < time2 && time1 < time3 then name1 + else if time2 < time3 then name2 + else name3); + Printf.printf "╚═══════════════════════════════════════════════════════╝\n\n" + + | _ -> + Printf.printf " ✗ Unexpected pill structure\n" |