changeset 1172:34446df5733f tooling/benchmarks

Add run_and_view script
author Jonatan Werpers <jonatan@werpers.com>
date Wed, 25 Jan 2023 12:52:09 +0100
parents 87bc91def1ff
children 7bbd79d62840
files .hgignore benchmark/Manifest.toml benchmark/Project.toml benchmark/benchmarks.jl benchmark/result.tmpl benchmark/run_and_view.jl
diffstat 6 files changed, 313 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
diff -r 87bc91def1ff -r 34446df5733f .hgignore
--- a/.hgignore	Tue Jan 24 21:57:24 2023 +0100
+++ b/.hgignore	Wed Jan 25 12:52:09 2023 +0100
@@ -1,3 +1,4 @@
 syntax: glob
 docs/build/
 docs/build-local/
+benchmark/results
diff -r 87bc91def1ff -r 34446df5733f benchmark/Manifest.toml
--- a/benchmark/Manifest.toml	Tue Jan 24 21:57:24 2023 +0100
+++ b/benchmark/Manifest.toml	Wed Jan 25 12:52:09 2023 +0100
@@ -2,7 +2,7 @@
 
 julia_version = "1.8.2"
 manifest_format = "2.0"
-project_hash = "8aa1ffedc584f62ec0f73611b77967c9fcf3bf98"
+project_hash = "25bba7b4a00465d5a2b00b589eb10e3301c31f2a"
 
 [[deps.AbstractTrees]]
 git-tree-sha1 = "faa260e4cb5aba097a73fab382dd4b5819d8ec8c"
@@ -54,6 +54,16 @@
 uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae"
 version = "0.5.2+0"
 
+[[deps.DataAPI]]
+git-tree-sha1 = "e8119c1a33d267e16108be441a287a6981ba1630"
+uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a"
+version = "1.14.0"
+
+[[deps.DataValueInterfaces]]
+git-tree-sha1 = "bfc1187b79289637fa0ef6d4436ebdfe6905cbd6"
+uuid = "e2d170a0-9d28-54be-80f0-106bbe20a464"
+version = "1.0.0"
+
 [[deps.Dates]]
 deps = ["Printf"]
 uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"
@@ -75,6 +85,11 @@
 deps = ["Markdown"]
 uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
 
+[[deps.IteratorInterfaceExtensions]]
+git-tree-sha1 = "a3f24677c21f5bbe9d2a714f95dcd58337fb2856"
+uuid = "82899510-4779-5014-852e-03e436cf321d"
+version = "1.0.0"
+
 [[deps.JSON]]
 deps = ["Dates", "Mmap", "Parsers", "Unicode"]
 git-tree-sha1 = "3c837543ddb02250ef42f4738347454f95079d4e"
@@ -132,6 +147,12 @@
 uuid = "14a3606d-f60d-562e-9121-12d972cd8159"
 version = "2022.2.1"
 
+[[deps.Mustache]]
+deps = ["Printf", "Tables"]
+git-tree-sha1 = "1e566ae913a57d0062ff1af54d2697b9344b99cd"
+uuid = "ffc61752-8dc7-55ee-8c37-f3e9cdd09e70"
+version = "1.0.14"
+
 [[deps.NetworkOptions]]
 uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908"
 version = "1.2.0"
@@ -147,6 +168,11 @@
 uuid = "4536629a-c528-5b80-bd46-f80d51c5b363"
 version = "0.3.20+0"
 
+[[deps.OrderedCollections]]
+git-tree-sha1 = "85f8e6578bf1f9ee0d11e7bb1b1456435479d47c"
+uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
+version = "1.4.1"
+
 [[deps.Parsers]]
 deps = ["Dates", "SnoopPrecompile"]
 git-tree-sha1 = "8175fc2b118a3755113c8e68084dc1a9e63c61ee"
@@ -237,6 +263,18 @@
 uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
 version = "1.0.0"
 
+[[deps.TableTraits]]
+deps = ["IteratorInterfaceExtensions"]
+git-tree-sha1 = "c06b2f539df1c6efa794486abfb6ed2022561a39"
+uuid = "3783bdb8-4a98-5b6b-af9a-565f29a5fe9c"
+version = "1.0.1"
+
+[[deps.Tables]]
+deps = ["DataAPI", "DataValueInterfaces", "IteratorInterfaceExtensions", "LinearAlgebra", "OrderedCollections", "TableTraits", "Test"]
+git-tree-sha1 = "c79322d36826aa2f4fd8ecfa96ddb47b174ac78d"
+uuid = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
+version = "1.10.0"
+
 [[deps.Tar]]
 deps = ["ArgTools", "SHA"]
 uuid = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e"
@@ -248,6 +286,10 @@
 uuid = "5d786b92-1e48-4d6f-9151-6b4477ca9bed"
 version = "0.1.6"
 
+[[deps.Test]]
+deps = ["InteractiveUtils", "Logging", "Random", "Serialization"]
+uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
+
 [[deps.TiledIteration]]
 deps = ["ArrayInterface", "OffsetArrays"]
 git-tree-sha1 = "1bf2bb587a7fc99fefac2ff076b18b500128e9c0"
diff -r 87bc91def1ff -r 34446df5733f benchmark/Project.toml
--- a/benchmark/Project.toml	Tue Jan 24 21:57:24 2023 +0100
+++ b/benchmark/Project.toml	Wed Jan 25 12:52:09 2023 +0100
@@ -1,4 +1,5 @@
 [deps]
 BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
+Mustache = "ffc61752-8dc7-55ee-8c37-f3e9cdd09e70"
 PkgBenchmark = "32113eaa-f34f-5b0d-bd6c-c81e245fc73d"
 Sbplib = "5a373a26-915f-4769-bcab-bf03835de17b"
diff -r 87bc91def1ff -r 34446df5733f benchmark/benchmarks.jl
--- a/benchmark/benchmarks.jl	Tue Jan 24 21:57:24 2023 +0100
+++ b/benchmark/benchmarks.jl	Wed Jan 25 12:52:09 2023 +0100
@@ -26,12 +26,7 @@
 
 SUITE
 
-
-# TODO: Make it easy to run and display results (useful to look at them in a webbrowser? Could serve them using julia)
+# TODO: Add mercurial version of benchmarkpkg
 # TODO: Make it easy to compare different commits. (A simple script?)
-# TODO: Do we need machanisms to save the results from runs?
-# TBD: How well does BenchmarkTools work for comparisons, do we need make special considerations?
-# TBD: When and how do we want to look at % of peak performance? Is this going to be done using the benchmark suite?
-
 
 # Should set HGPLAIN before script use. Example: `HGPLAIN= hg st`
diff -r 87bc91def1ff -r 34446df5733f benchmark/result.tmpl
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/benchmark/result.tmpl	Wed Jan 25 12:52:09 2023 +0100
@@ -0,0 +1,211 @@
+<html>
+<head>
+    <title>Benchmark result {{title}}</title>
+    <meta charset="UTF-8">
+
+    <style>
+        @charset "UTF-8";
+        body {
+        font-family: system-ui, -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
+            line-height: 1.4;
+            max-width: 800px;
+            margin: 20px auto;
+            padding: 0 10px;
+            color: #363636;
+            background: #fff;
+            text-rendering:optimizeLegibility
+        }
+
+        button, input, textarea {
+            transition:background-color .1s linear, border-color .1s linear, color .1s linear, box-shadow .1s linear, transform .1s ease
+        }
+
+        h1 {
+            font-size: 2.2em;
+            margin-top:0
+        }
+
+        h1, h2, h3, h4, h5, h6 {
+            margin-bottom:12px
+        }
+
+        h1, h2, h3, h4, h5, h6, strong {
+            color:#000
+        }
+
+        b, h1, h2, h3, h4, h5, h6, strong, th {
+            font-weight:600
+        }
+
+        blockquote {
+            border-left: 4px solid rgba(0, 150, 191, .67);
+            margin: 1.5em 0;
+            padding: .5em 1em;
+            font-style:italic
+        }
+
+        blockquote > footer {
+            margin-top: 10px;
+            font-style:normal
+        }
+
+        address, blockquote cite {
+            font-style:normal
+        }
+
+        a[href^=mailto]:before {
+            content: "📧 "
+        }
+
+        a[href^=tel]:before {
+            content: "📞 "
+        }
+
+        a[href^=sms]:before {
+            content: "💬 "
+        }
+
+        button, input[type=button], input[type=checkbox], input[type=submit] {
+            cursor:pointer
+        }
+
+        input:not([type=checkbox]):not([type=radio]), select {
+            display:block
+        }
+
+        button, input, select, textarea {
+            color: #000;
+            background-color: #efefef;
+            font-family: inherit;
+            font-size: inherit;
+            margin-right: 6px;
+            margin-bottom: 6px;
+            padding: 10px;
+            border: none;
+            border-radius: 6px;
+            outline:none
+        }
+
+        button, input:not([type=checkbox]):not([type=radio]), select, textarea {
+            -webkit-appearance:none
+        }
+
+        textarea {
+            margin-right: 0;
+            width: 100%;
+            box-sizing: border-box;
+            resize:vertical
+        }
+
+        button, input[type=button], input[type=submit] {
+            padding-right: 30px;
+            padding-left:30px
+        }
+
+        button:hover, input[type=button]:hover, input[type=submit]:hover {
+            background:#ddd
+        }
+
+        button:focus, input:focus, select:focus, textarea:focus {
+            box-shadow:0 0 0 2px rgba(0, 150, 191, .67)
+        }
+
+        button:active, input[type=button]:active, input[type=checkbox]:active, input[type=radio]:active, input[type=submit]:active {
+            transform:translateY(2px)
+        }
+
+        button:disabled, input:disabled, select:disabled, textarea:disabled {
+            cursor: not-allowed;
+            opacity:.5
+        }
+
+        ::-webkit-input-placeholder {
+            color:#949494
+        }
+
+        :-ms-input-placeholder {
+            color:#949494
+        }
+
+        ::-ms-input-placeholder {
+            color:#949494
+        }
+
+        ::placeholder {
+            color:#949494
+        }
+
+        a {
+            text-decoration: none;
+            color:#0076d1
+        }
+
+        a:hover {
+            text-decoration:underline
+        }
+
+        code, kbd {
+            background: #efefef;
+            color: #000;
+            padding: 5px;
+            border-radius:6px
+        }
+
+        pre > code {
+            padding: 10px;
+            display: block;
+            overflow-x:auto
+        }
+
+        img {
+            max-width:100%
+        }
+
+        hr {
+            border: none;
+            border-top:1px solid #dbdbdb
+        }
+
+        table {
+            border-collapse: collapse;
+            margin-bottom: 10px;
+            width:100%
+        }
+
+        td, th {
+            padding: 6px;
+            text-align:left
+        }
+
+        th {
+            border-bottom:1px solid #dbdbdb
+        }
+
+        tbody tr:nth-child(2n) {
+            background-color:#efefef
+        }
+
+        ::-webkit-scrollbar {
+            height: 10px;
+            width:10px
+        }
+
+        ::-webkit-scrollbar-track {
+            background: #efefef;
+            border-radius:6px
+        }
+
+        ::-webkit-scrollbar-thumb {
+            background: #d5d5d5;
+            border-radius:6px
+        }
+
+        ::-webkit-scrollbar-thumb:hover {
+            background: #c4c4c4
+        }
+    </style>
+</head>
+<body>
+    {{{content}}}
+</body>
+</html>
diff -r 87bc91def1ff -r 34446df5733f benchmark/run_and_view.jl
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/benchmark/run_and_view.jl	Wed Jan 25 12:52:09 2023 +0100
@@ -0,0 +1,56 @@
+using PkgBenchmark
+using Markdown
+using Mustache
+
+import Sbplib
+
+# From Pluto.jl/src/webserver/WebServer.jl  (2023-01-24)
+function open_in_default_browser(url::AbstractString)::Bool
+    try
+        if Sys.isapple()
+            Base.run(`open $url`)
+            true
+        elseif Sys.iswindows() || detectwsl()
+            Base.run(`powershell.exe Start "'$url'"`)
+            true
+        elseif Sys.islinux()
+            Base.run(`xdg-open $url`)
+            true
+        else
+            false
+        end
+    catch ex
+        false
+    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")
+
+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