summaryrefslogtreecommitdiff
path: root/ocaml/test/cache_solid.ml
diff options
context:
space:
mode:
Diffstat (limited to 'ocaml/test/cache_solid.ml')
-rw-r--r--ocaml/test/cache_solid.ml43
1 files changed, 43 insertions, 0 deletions
diff --git a/ocaml/test/cache_solid.ml b/ocaml/test/cache_solid.ml
new file mode 100644
index 0000000..f82e0b8
--- /dev/null
+++ b/ocaml/test/cache_solid.ml
@@ -0,0 +1,43 @@
+(* 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 pill = Serial.cue pill_bytes in
+ let elapsed = Unix.gettimeofday () -. start in
+ Printf.printf " ✓ Cued in %.1fs\n\n" elapsed;
+
+ 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