-
-
Notifications
You must be signed in to change notification settings - Fork 64
Render summary benchmark results as Markdown tables #621
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| # Constantine | ||
| # Copyright (c) 2018-2019 Status Research & Development GmbH | ||
| # Copyright (c) 2020-Present Mamy Andre-Ratsimbazafy | ||
| # Licensed and distributed under either of | ||
| # * MIT license (license terms in the root directory or at http://opensource.org/licenses/MIT). | ||
| # * Apache v2 license (license terms in the root directory or at http://www.apache.org/licenses/LICENSE-2.0). | ||
| # at your option. This file may not be copied, modified, or distributed except according to those terms. | ||
|
|
||
| import std/strutils | ||
|
|
||
| var printedMarkdownHeaders: seq[string] | ||
|
|
||
| func markdownEscape*(cell: string): string = | ||
| cell.multiReplace( | ||
| ("\\", "\\\\"), | ||
| ("|", "\\|"), | ||
| ("\r", ""), | ||
| ("\n", "<br>") | ||
| ) | ||
|
|
||
| func markdownTableHeader*(headers: openArray[string]): string = | ||
| result = "|" | ||
| for header in headers: | ||
| result.add " " & markdownEscape(header) & " |" | ||
|
|
||
| func markdownTableSeparator*(columns: int): string = | ||
| result = "|" | ||
| for _ in 0 ..< columns: | ||
| result.add " --- |" | ||
|
|
||
| func markdownTableRow*(cells: openArray[string]): string = | ||
| result = "|" | ||
| for cell in cells: | ||
| result.add " " & markdownEscape(cell) & " |" | ||
|
|
||
| proc reportMarkdownTable*(headers, cells: openArray[string]) = | ||
| doAssert headers.len == cells.len | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| let key = headers.join("\t") | ||
| for printedHeader in printedMarkdownHeaders: | ||
| if printedHeader == key: | ||
| echo markdownTableRow(cells) | ||
| return | ||
|
|
||
| echo markdownTableHeader(headers) | ||
| echo markdownTableSeparator(headers.len) | ||
| printedMarkdownHeaders.add key | ||
| echo markdownTableRow(cells) | ||
|
Comment on lines
+36
to
+48
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because To support multiple separate tables with identical headers, we should expose a helper function to reset/clear the printed headers tracker.
Comment on lines
+36
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -410,6 +410,7 @@ const testDesc: seq[tuple[path: string, useGMP: bool]] = @[ | |
| # KDF | ||
| # ---------------------------------------------------------- | ||
| ("tests/t_kdf_hkdf.nim", false), | ||
| ("tests/t_bench_report.nim", false), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||
|
|
||
| # Primitives | ||
| # ---------------------------------------------------------- | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # Constantine | ||
| # Copyright (c) 2018-2019 Status Research & Development GmbH | ||
| # Copyright (c) 2020-Present Mamy Andre-Ratsimbazafy | ||
| # Licensed and distributed under either of | ||
| # * MIT license (license terms in the root directory or at http://opensource.org/licenses/MIT). | ||
| # * Apache v2 license (license terms in the root directory or at http://www.apache.org/licenses/LICENSE-2.0). | ||
| # at your option. This file may not be copied, modified, or distributed except according to those terms. | ||
|
|
||
| import | ||
| std/unittest, | ||
| ../benchmarks/bench_report | ||
|
|
||
| suite "Benchmark Markdown reports": | ||
| test "renders a Markdown table header": | ||
| check markdownTableHeader(["Operation", "Domain"]) == "| Operation | Domain |" | ||
| check markdownTableSeparator(2) == "| --- | --- |" | ||
|
|
||
| test "escapes Markdown table cells": | ||
| check markdownTableRow(["A | B", "line 1\nline 2"]) == "| A \\| B | line 1<br>line 2 |" | ||
|
Comment on lines
+18
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The test exercises pipe ( Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thread-safety concern and unbounded memory growth.
The module-level
printedMarkdownHeaderscache is not thread-safe and will grow unboundedly in long-running processes. If benchmarks are run concurrently or the process executes many different benchmark suites, this could cause issues.Consider either:
{.threadvar.}if each thread should have its own cache, orclearMarkdownCache()proc), orHashSet[string]with a maximum size limit🔒 Example: Thread-local cache
Or with explicit management:
📝 Committable suggestion
🤖 Prompt for AI Agents