summaryrefslogtreecommitdiff
path: root/ocaml/test/old/cache_solid.ml
diff options
context:
space:
mode:
Diffstat (limited to 'ocaml/test/old/cache_solid.ml')
-rw-r--r--ocaml/test/old/cache_solid.ml78
1 files changed, 78 insertions, 0 deletions
diff --git a/ocaml/test/old/cache_solid.ml b/ocaml/test/old/cache_solid.ml
new file mode 100644
index 0000000..7ad7df0
--- /dev/null
+++ b/ocaml/test/old/cache_solid.ml
@@ -0,0 +1,78 @@
+(* Cache Solid Pill - Cue once and save marshalled OCaml noun
+ *
+ * This cues the solid pill once (slow) and saves the resulting
+ * noun using OCaml's Marshal for fast loading later
+ *)
+
+open Nock_lib
+
+let cache_solid env =
+ Printf.printf "Caching solid pill...\n\n";
+
+ Eio.Switch.run @@ fun _sw ->
+ let fs = Eio.Stdenv.fs env in
+
+ (* Load and cue solid pill *)
+ Printf.printf "Step 1: Loading solid.pill (8.7 MB)...\n";
+ let file_path = Eio.Path.(fs / "solid.pill") in
+ let pill_bytes = Eio.Path.load file_path |> Bytes.of_string in
+ Printf.printf " Loaded %d bytes\n\n" (Bytes.length pill_bytes);
+
+ Printf.printf "Step 2: Cuing (this will take several minutes)...\n";
+ let start = Unix.gettimeofday () in
+ let last_tick = ref start in
+ let last_nouns = ref 0 in
+ let last_depth = ref 0 in
+ let last_peak = ref 0 in
+ let bytes_seen = ref 0 in
+
+ let total_bytes = Bytes.length pill_bytes in
+
+ let progress ~nouns ~bits ~depth ~max_depth =
+ last_nouns := nouns;
+ last_depth := depth;
+ last_peak := max_depth;
+ bytes_seen := bits / 8;
+
+ let now = Unix.gettimeofday () in
+ if now -. !last_tick >= 1.0 then begin
+ let mb = float_of_int !bytes_seen /. (1024. *. 1024.) in
+ let pct = (float_of_int !bytes_seen /. float_of_int total_bytes) *. 100. in
+ Printf.printf " %.1fs | %.2f MiB (%.1f%%) | nouns=%d depth=%d/%d\n%!"
+ (now -. start) mb pct !last_nouns !last_depth !last_peak;
+ last_tick := now
+ end
+ in
+
+ let pill =
+ Serial.cue
+ ~progress
+ ~progress_interval:50_000
+ pill_bytes
+ in
+
+ let elapsed = Unix.gettimeofday () -. start in
+ Printf.printf
+ " ✓ Cued in %.1fs (%.2f MiB, nouns=%d, max depth=%d)\n\n"
+ elapsed
+ (float_of_int total_bytes /. (1024. *. 1024.))
+ !last_nouns
+ !last_peak;
+
+ Printf.printf "Step 3: Marshalling noun to solid.noun...\n";
+ let out_channel = open_out_bin "solid.noun" in
+ Marshal.to_channel out_channel pill [];
+ close_out out_channel;
+ Printf.printf " ✓ Saved to solid.noun\n\n";
+
+ Printf.printf "Step 4: Testing reload speed...\n";
+ let start = Unix.gettimeofday () in
+ let in_channel = open_in_bin "solid.noun" in
+ let _reloaded = (Marshal.from_channel in_channel : Noun.noun) in
+ close_in in_channel;
+ let elapsed = Unix.gettimeofday () -. start in
+ Printf.printf " ✓ Reloaded in %.4fs (much faster!)\n\n" elapsed;
+
+ Printf.printf "Done! Use solid.noun for fast testing.\n"
+
+let () = Eio_main.run cache_solid