changeset 1174:50c31500eb97 tooling/benchmarks

Clean up run_and_view
author Jonatan Werpers <jonatan@werpers.com>
date Wed, 25 Jan 2023 13:22:51 +0100
parents 7bbd79d62840
children a0ab801b62c2
files benchmark/benchmarks.jl benchmark/run_and_view.jl
diffstat 2 files changed, 44 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/benchmark/benchmarks.jl	Wed Jan 25 13:05:15 2023 +0100
+++ b/benchmark/benchmarks.jl	Wed Jan 25 13:22:51 2023 +0100
@@ -30,3 +30,5 @@
 # TODO: Make it easy to compare different commits. (A simple script?)
 
 # Should set HGPLAIN before script use. Example: `HGPLAIN= hg st`
+# `hg id` for getting the revision
+# `hg update --check` for updating, requires a clean working directory.
--- a/benchmark/run_and_view.jl	Wed Jan 25 13:05:15 2023 +0100
+++ b/benchmark/run_and_view.jl	Wed Jan 25 13:22:51 2023 +0100
@@ -1,9 +1,47 @@
-using PkgBenchmark
-using Markdown
-using Mustache
+import PkgBenchmark
+import Markdown
+import Mustache
+import Dates
 
 import Sbplib
 
+const sbplib_root = splitpath(pathof(Sbplib))[1:end-2] |> joinpath
+const results_dir = mkpath(joinpath(sbplib_root, "benchmark/results"))
+const template_path = joinpath(sbplib_root, "benchmark/result.tmpl")
+
+function main()
+    r = run_benchmark()
+    file_path = write_result_html(r)
+    open_in_default_browser(file_path)
+end
+
+function run_benchmark()
+    return PkgBenchmark.benchmarkpkg(Sbplib)
+end
+
+function write_result_html(io, r; title)
+    iobuffer = IOBuffer()
+    PkgBenchmark.export_markdown(iobuffer, r)
+
+    parsed_md = Markdown.parse(String(take!(iobuffer)))
+    content = Markdown.html(parsed_md)
+
+    template = Mustache.load(template_path)
+    Mustache.render(io, template, Dict("title"=>title, "content"=>content))
+end
+
+function write_result_html(r)
+    dt = Dates.format(Dates.now(), "yyyy-mm-dd HH:MM:SS")
+    file_path = joinpath(results_dir, dt*".html")
+
+    open(file_path, "w") do io
+        write_result_html(io, r; title=dt)
+    end
+
+    return file_path
+end
+
+
 # From Pluto.jl/src/webserver/WebServer.jl  (2023-01-24)
 function open_in_default_browser(url::AbstractString)::Bool
     try
@@ -24,33 +62,7 @@
     end
 end
 
-r = benchmarkpkg(Sbplib)
-
-iobuffer = IOBuffer()
-export_markdown(iobuffer, r)
-
-parsed_md = Markdown.parse(String(take!(iobuffer)))
-
-sbplib_root = splitpath(pathof(Sbplib))[1:end-2] |> joinpath
-
-results_dir = mkpath(joinpath(sbplib_root, "benchmark/results"))
-
-dt = Dates.format(now(), "yyyy-mm-dd HH:MM:SS")
+main
 
-file_path = joinpath(results_dir, dt*".html")
-
-
-template = Mustache.load(joinpath(sbplib_root, "benchmark/result.tmpl"))
-
-open(file_path, "w") do io
-    content = html(parsed_md)
-    Mustache.render(io, template, Dict("title"=>dt, "content"=>content))
-    # html(io, parsed_md)
-end
-
-open_in_default_browser(file_path)
-
-
-# TODO: Cleanup code
 # TODO: Change color of codeblocks
 # TODO: Change width of tables and code blocks