Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: add synthetic benchmark #7189

Merged
merged 12 commits into from
Feb 28, 2023
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
name: Melange demo app build time benchmark
name: Build time benchmarks

# Do not run this workflow on pull request since this workflow has permission to modify contents.
on:
push:
branches:
- main
- bench/add-synthetic-benchmark

permissions:
# deployments permission to deploy GitHub pages website
Expand Down Expand Up @@ -65,7 +66,7 @@ jobs:

- name: Run pupilfirst benchmark
working-directory: pupilfirst
run: ../bench/gen-melange-benchmark.sh 'opam exec -- ../_boot/dune.exe build --root=. @main' 'opam exec -- ../_boot/dune.exe clean --root=.' 'pupilfirst build time (${{ runner.os }})' > melange-benchmark-result.json
run: ../bench/gen-benchmark.sh 'opam exec -- ../_boot/dune.exe build --root=. @main' 'opam exec -- ../_boot/dune.exe clean --root=.' 'pupilfirst build time (${{ runner.os }})' > melange-benchmark-result.json

- name: Print pupilfirst benchmark results
working-directory: pupilfirst
Expand All @@ -82,7 +83,38 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}
auto-push: true
# Ratio indicating how worse the current benchmark result is.
# 150% means if last build took 40s and current takes 50s, it will trigger an alert
# 150% means if last build took 40s and current takes >60s, it will trigger an alert
alert-threshold: "150%"
fail-on-alert: true
# Enable alert commit comment
comment-on-alert: true
# Mention @jchavarri in the commit comment
alert-comment-cc-users: '@jchavarri'

- name: Create synthetic benchmark
working-directory: bench
run: opam exec -- ../_boot/dune.exe exec ./gen_synthetic.exe -- -n 2000 synthetic

- name: Run synthetic benchmark
working-directory: bench/synthetic
run: ../gen-benchmark.sh 'opam exec -- ../../_boot/dune.exe build @all' 'opam exec -- ../../_boot/dune.exe clean' 'synthetic build time (${{ runner.os }})' > synthetic-benchmark-result.json

- name: Print synthetic benchmark results
working-directory: bench/synthetic
run: |
cat bench.json
cat synthetic-benchmark-result.json

- name: Store synthetic benchmark result
uses: benchmark-action/github-action-benchmark@v1
with:
name: Synthetic Benchmark
tool: "customSmallerIsBetter"
output-file-path: bench/synthetic/synthetic-benchmark-result.json
github-token: ${{ secrets.GITHUB_TOKEN }}
auto-push: true
# Ratio indicating how worse the current benchmark result is.
# 150% means if last build took 40s and current takes >60s, it will trigger an alert
alert-threshold: "150%"
fail-on-alert: true
# Enable alert commit comment
Expand Down
6 changes: 6 additions & 0 deletions bench/dune
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
(executable
(name bench)
(modules bench)
(libraries dune_stats chrome_trace stdune fiber dune_engine dune_util))

(rule
(alias bench)
(action
(run ./bench.exe %{bin:dune})))

(executable
(modules gen_synthetic)
(libraries unix)
(name gen_synthetic))
File renamed without changes.
33 changes: 33 additions & 0 deletions bench/gen_synthetic.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
open Printf

let write_modules basedir num_modules =
for current_mod = 1 to num_modules do
let modname = sprintf "%s/m_%d" basedir current_mod in
let f = open_out (sprintf "%s.ml" modname) in
close_out f
done

let dune = {|
(library
(name test))
|}

let write basedir =
let () = Unix.mkdir basedir 0o777 in
let f = open_out (Filename.concat basedir "dune") in
output_string f dune;
let () = close_out f in
write_modules basedir

let () =
let basedir = ref "." in
let num_modules = ref 0 in
Arg.parse
[ ( "-n"
, Arg.Int (fun n -> num_modules := n)
, "<n> number of modules to include in the synthetic library" )
]
(fun d -> basedir := d)
(sprintf "usage: %s [basedir]" (Filename.basename Sys.argv.(0)));

write !basedir !num_modules