Skip to content

Commit

Permalink
pre+suf length measuring
Browse files Browse the repository at this point in the history
  • Loading branch information
disconcision committed Nov 14, 2024
1 parent edd3154 commit c5b001a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
30 changes: 20 additions & 10 deletions src/web/Benchmark.re
Original file line number Diff line number Diff line change
Expand Up @@ -74,26 +74,35 @@ let benchmark_parsing = () => {
};
};

let cursor_depth = (z: Zipper.t) => {
let cursor_depth = (z: Zipper.t): int => {
let cell = Zipper.zip(~save_cursor=true, z);
switch (cell.marks.cursor) {
| Some(Point(cursor)) => cursor.path |> List.length
| _ => failwith("benchmark: no cursor")
};
};

let pre_plus_suf_length = (z: Zipper.t): int => {
let ((pre, suf), _tl) = Ctx.uncons(z.ctx);
List.length(pre) + List.length(suf);
};

let benchmark_hole_fills = () => {
let program_str = Data.holey;
//let program_str = List.fold_left((++), "", List.init(40, _ => Data.base1));
let num_holes = 20; //40
let reps_per_action = 200;
let zipper_action = Modify.insert("X");

print_endline("BENCHMARK: filling hole edits at different depths");
let a = benchmark(program_str);
print_endline("BENCHMARK: warmup parse: " ++ string_of_int(a) ++ "ms");
let b = benchmark(program_str);
print_endline(
"BENCHMARK: same parse after warmup: " ++ string_of_int(b) ++ "ms",
);
print_endline("init program, parsed and then stringed:");
print_endline(program_str |> Store.parse |> Zipper.to_string);
// let a = benchmark(program_str);
// print_endline("BENCHMARK: warmup parse: " ++ string_of_int(a) ++ "ms");
// let b = benchmark(program_str);
// print_endline(
// "BENCHMARK: same parse after warmup: " ++ string_of_int(b) ++ "ms",
// );
let z =
List.fold_left(
(z_acc, _x) => {
Expand All @@ -106,7 +115,9 @@ let benchmark_hole_fills = () => {
}
});
print_endline(
"depth: "
"presuf: "
++ string_of_int(pre_plus_suf_length(z_acc))
++ ", depth: "
++ string_of_int(cursor_depth(z_acc))
++ ", "
++ "time for "
Expand All @@ -124,12 +135,11 @@ let benchmark_hole_fills = () => {
},
// starts at bottom of holey program
Store.parse(program_str),
List.init(20, _ => ()),
List.init(num_holes, _ => ()),
);
();
print_endline("program after actions:");
print_endline(z |> Zipper.to_string);
};

//benchmark_parsing();
benchmark_hole_fills();
12 changes: 12 additions & 0 deletions src/web/Data.re
Original file line number Diff line number Diff line change
Expand Up @@ -583,3 +583,15 @@ let r = dist(center, p) in
circle( , r) in
|};

let base1 = {|let = 1 in
|};

let base1' = base1 ++ base1 ++ base1 ++ base1 ++ base1;

let base2 = {|let x = + 2 in
let x = + 2 * 3 in
let x = + 2 / 3 + 4 in
let x = 1 + 2 + + 4 + 5 in
let x = 1 + 2 * 3 + + 5 + 6 in
|};
2 changes: 2 additions & 0 deletions src/web/Main.re
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,5 @@ Incr_dom.Start_app.start(
~bind_to_element_with_id="container",
~initial_model=Model.init_from_store(),
);

Benchmark.benchmark_hole_fills();
2 changes: 1 addition & 1 deletion src/web/Store.re
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ let save_syntax_key: int => string =
let save_syntax = (save_idx: int, z: Zipper.t) =>
LocalStorage.set(save_syntax_key(save_idx), z |> serialize);

let tasks = [Data.holey]; //Data.longlong,
let tasks = [Data.base1']; //Data.longlong,
//Data.epzz,
// Data.epz0,
// Data.epz1,
Expand Down

0 comments on commit c5b001a

Please sign in to comment.