Mercurial > repos > public > sbplib_julia
comparison benchmark/run_and_view.jl @ 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 | 34446df5733f |
children | a0ab801b62c2 |
comparison
equal
deleted
inserted
replaced
1173:7bbd79d62840 | 1174:50c31500eb97 |
---|---|
1 using PkgBenchmark | 1 import PkgBenchmark |
2 using Markdown | 2 import Markdown |
3 using Mustache | 3 import Mustache |
4 import Dates | |
4 | 5 |
5 import Sbplib | 6 import Sbplib |
7 | |
8 const sbplib_root = splitpath(pathof(Sbplib))[1:end-2] |> joinpath | |
9 const results_dir = mkpath(joinpath(sbplib_root, "benchmark/results")) | |
10 const template_path = joinpath(sbplib_root, "benchmark/result.tmpl") | |
11 | |
12 function main() | |
13 r = run_benchmark() | |
14 file_path = write_result_html(r) | |
15 open_in_default_browser(file_path) | |
16 end | |
17 | |
18 function run_benchmark() | |
19 return PkgBenchmark.benchmarkpkg(Sbplib) | |
20 end | |
21 | |
22 function write_result_html(io, r; title) | |
23 iobuffer = IOBuffer() | |
24 PkgBenchmark.export_markdown(iobuffer, r) | |
25 | |
26 parsed_md = Markdown.parse(String(take!(iobuffer))) | |
27 content = Markdown.html(parsed_md) | |
28 | |
29 template = Mustache.load(template_path) | |
30 Mustache.render(io, template, Dict("title"=>title, "content"=>content)) | |
31 end | |
32 | |
33 function write_result_html(r) | |
34 dt = Dates.format(Dates.now(), "yyyy-mm-dd HH:MM:SS") | |
35 file_path = joinpath(results_dir, dt*".html") | |
36 | |
37 open(file_path, "w") do io | |
38 write_result_html(io, r; title=dt) | |
39 end | |
40 | |
41 return file_path | |
42 end | |
43 | |
6 | 44 |
7 # From Pluto.jl/src/webserver/WebServer.jl (2023-01-24) | 45 # From Pluto.jl/src/webserver/WebServer.jl (2023-01-24) |
8 function open_in_default_browser(url::AbstractString)::Bool | 46 function open_in_default_browser(url::AbstractString)::Bool |
9 try | 47 try |
10 if Sys.isapple() | 48 if Sys.isapple() |
22 catch ex | 60 catch ex |
23 false | 61 false |
24 end | 62 end |
25 end | 63 end |
26 | 64 |
27 r = benchmarkpkg(Sbplib) | 65 main |
28 | 66 |
29 iobuffer = IOBuffer() | |
30 export_markdown(iobuffer, r) | |
31 | |
32 parsed_md = Markdown.parse(String(take!(iobuffer))) | |
33 | |
34 sbplib_root = splitpath(pathof(Sbplib))[1:end-2] |> joinpath | |
35 | |
36 results_dir = mkpath(joinpath(sbplib_root, "benchmark/results")) | |
37 | |
38 dt = Dates.format(now(), "yyyy-mm-dd HH:MM:SS") | |
39 | |
40 file_path = joinpath(results_dir, dt*".html") | |
41 | |
42 | |
43 template = Mustache.load(joinpath(sbplib_root, "benchmark/result.tmpl")) | |
44 | |
45 open(file_path, "w") do io | |
46 content = html(parsed_md) | |
47 Mustache.render(io, template, Dict("title"=>dt, "content"=>content)) | |
48 # html(io, parsed_md) | |
49 end | |
50 | |
51 open_in_default_browser(file_path) | |
52 | |
53 | |
54 # TODO: Cleanup code | |
55 # TODO: Change color of codeblocks | 67 # TODO: Change color of codeblocks |
56 # TODO: Change width of tables and code blocks | 68 # TODO: Change width of tables and code blocks |