Skip to content

Commit

Permalink
Add better structure for bench
Browse files Browse the repository at this point in the history
  • Loading branch information
davesnx committed Aug 8, 2024
1 parent b3bec6b commit 2c13ad4
Show file tree
Hide file tree
Showing 7 changed files with 452 additions and 34 deletions.
12 changes: 10 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,18 @@ docs-open: ## Open odoc docs with default web browser
.PHONY: docs-serve
docs-serve: docs docs-open ## Open odoc docs with default web browser

.PHONY: build-bench
build-bench: ## Run benchmark
$(DUNE) build bench --profile=release

.PHONY: bench
bench: ## Run benchmark
bench: build-bench ## Run benchmark
$(DUNE) exec bench/main.exe --profile=release --display-separate-messages --no-print-directory

.PHONY: bench-watch
bench-watch: ## Run benchmark in watch mode
bench-watch: build-bench ## Run benchmark in watch mode
$(DUNE) exec bench/main.exe --profile=release --display-separate-messages --no-print-directory --watch

.PHONY: once
once: build-bench ## Run benchmark once
@time _build/default/bench/once.exe
Empty file added bench/.keep
Empty file.
17 changes: 15 additions & 2 deletions bench/dune
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
(executable
(name bench)
(libraries core_bench core_unix.command_unix))
(name main)
(modules main)
(libraries
core_bench
server-reason-react.react
server-reason-react.reactDom)
(preprocess
(pps server-reason-react.ppx)))

(executable
(name once)
(modules once)
(libraries server-reason-react.react server-reason-react.reactDom)
(preprocess
(pps server-reason-react.ppx)))
65 changes: 36 additions & 29 deletions bench/main.re
Original file line number Diff line number Diff line change
@@ -1,37 +1,44 @@
open Core;
open Core_bench;
module Bench = Core_bench.Bench;

module App = {
module TinyApp = {
[@react.component]
let make = () => {
<div className=["py-16 px-12"]>
<h1 className="font-bold text-4xl">
{React.string("Home of the demos")}
</h1>
<ul className="flex flex-col gap-4">
<li>
<a href="https://sancho.dev">
{React.string("https://sancho.dev")}
</a>
</li>
<li>
<a href="https://sancho.dev">
{React.string("https://sancho.dev")}
</a>
</li>
<li>
<a href="https://sancho.dev">
{React.string("https://sancho.dev")}
</a>
</li>
</ul>
</div>;
<html>
<body>
<h1> {React.string("Hello World")} </h1>
<p> {React.string("This is an example")} </p>
</body>
</html>;
};
};

let bench_static =
Bench.Test.create(~name="Parse static", () =>
ReactDOM.renderToStaticMarkup(<App />)
let bench_static_markup_with_simple_app =
Bench.Test.create(~name="bench_static_markup_with_simple_app", () =>
ReactDOM.renderToStaticMarkup(<TinyApp />)
);

Command_unix.run @@ Bench.make_command([bench_static]);
let main = tests => {
Printf.printf("\n\nRunning benchmarks\n");
Bench.bench(
~analysis_configs=
Bench.Analysis_config.default
|> List.map(
Bench.Analysis_config.with_error_estimation(
~bootstrap_trials=10000,
),
),
~run_config=
Bench.Run_config.create(
~quota=Bench.Quota.Num_calls(100000),
~stabilize_gc_between_runs=true,
~fork_each_benchmark=true,
(),
),
~save_to_file=
measurement =>
"bench/results/" ++ Bench.Measurement.name(measurement) ++ ".csv",
tests,
);
};

main([bench_static_markup_with_simple_app]);
13 changes: 13 additions & 0 deletions bench/once.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module TinyApp = {
[@react.component]
let make = () => {
<html>
<body>
<h1> {React.string("Hello World")} </h1>
<p> {React.string("This is an example")} </p>
</body>
</html>;
};
};

print_endline(ReactDOM.renderToStaticMarkup(<TinyApp />));
Loading

0 comments on commit 2c13ad4

Please sign in to comment.