Skip to content

Instantly share code, notes, and snippets.

@stedolan
Created February 11, 2025 11:33
Show Gist options
  • Save stedolan/b0e8d75402daa18dbffe53c00cf6e620 to your computer and use it in GitHub Desktop.
Save stedolan/b0e8d75402daa18dbffe53c00cf6e620 to your computer and use it in GitHub Desktop.
let table = Array.init 10_000 (fun _ -> Bytes.make 1_000 'a')
let writes =
Option.map bool_of_string (Sys.getenv_opt "WRITES")
|> Option.value ~default:false
let[@inline never] f () =
List.init (Array.length table) (fun i ->
let buf = table.(i) in
if writes then table.(i) <- buf;
Bytes.get buf 42)
let () =
for i = 1 to 10_000 do
ignore (Sys.opaque_identity (f ()))
done;
let stat = Gc.quick_stat () in
Printf.printf "%15s: %b\n%15s: %.0f\n%15s: %.0f\n%15s: %d\n%15s: %d\n"
"writes" writes
"minor_words" stat.minor_words
"major_words" stat.major_words
"cycles" stat.major_collections
"heap_words" stat.top_heap_words
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment