From 77f3862df44d71c6eab9a7f4b30154046a9c3c62 Mon Sep 17 00:00:00 2001
From: Thomas Pelletier
Date: Mon, 23 Mar 2026 22:00:18 -0400
Subject: [PATCH] Fix benchmark script replacing internal package imports
(#1042)
* Fix benchmark script replacing internal package imports
The sed command in bench() was replacing all occurrences of the go-toml
module path, including sub-package imports like internal/assert. This
caused the BurntSushi/toml benchmark to fail because it tried to import
github.com/BurntSushi/toml/internal/assert which doesn't exist.
Fix by anchoring the sed pattern to only match the import path when
followed by a closing quote, preserving internal package imports.
Also add a guard in the benchstathtml Python script to give a clear
error instead of an IndexError when no benchmark results are available.
https://claude.ai/code/session_016JGASo49PeFSfCaDxvrGFE
* Update benchmark results in README
https://claude.ai/code/session_016JGASo49PeFSfCaDxvrGFE
---------
Co-authored-by: Claude
---
README.md | 34 +++++++++++++++++-----------------
ci.sh | 7 ++++++-
2 files changed, 23 insertions(+), 18 deletions(-)
diff --git a/README.md b/README.md
index 8cc9542..f5f173e 100644
--- a/README.md
+++ b/README.md
@@ -239,12 +239,12 @@ Execution time speedup compared to other Go TOML libraries:
| Benchmark | go-toml v1 | BurntSushi/toml |
- | Marshal/HugoFrontMatter-2 | 1.9x | 2.2x |
- | Marshal/ReferenceFile/map-2 | 1.7x | 2.1x |
- | Marshal/ReferenceFile/struct-2 | 2.2x | 3.0x |
- | Unmarshal/HugoFrontMatter-2 | 2.9x | 2.7x |
- | Unmarshal/ReferenceFile/map-2 | 2.6x | 2.7x |
- | Unmarshal/ReferenceFile/struct-2 | 4.6x | 5.1x |
+ | Marshal/HugoFrontMatter-2 | 2.1x | 2.0x |
+ | Marshal/ReferenceFile/map-2 | 1.9x | 2.0x |
+ | Marshal/ReferenceFile/struct-2 | 2.3x | 2.5x |
+ | Unmarshal/HugoFrontMatter-2 | 3.4x | 2.8x |
+ | Unmarshal/ReferenceFile/map-2 | 3.0x | 3.0x |
+ | Unmarshal/ReferenceFile/struct-2 | 4.9x | 5.1x |
See more
@@ -257,17 +257,17 @@ provided for completeness.
| Benchmark | go-toml v1 | BurntSushi/toml |
- | Marshal/SimpleDocument/map-2 | 1.8x | 2.7x |
- | Marshal/SimpleDocument/struct-2 | 2.7x | 3.8x |
- | Unmarshal/SimpleDocument/map-2 | 3.8x | 3.0x |
- | Unmarshal/SimpleDocument/struct-2 | 5.6x | 4.1x |
- | UnmarshalDataset/example-2 | 3.0x | 3.2x |
- | UnmarshalDataset/code-2 | 2.3x | 2.9x |
- | UnmarshalDataset/twitter-2 | 2.6x | 2.7x |
- | UnmarshalDataset/citm_catalog-2 | 2.2x | 2.3x |
- | UnmarshalDataset/canada-2 | 1.8x | 1.5x |
- | UnmarshalDataset/config-2 | 4.1x | 2.9x |
- | geomean | 2.7x | 2.8x |
+ | Marshal/SimpleDocument/map-2 | 2.0x | 2.9x |
+ | Marshal/SimpleDocument/struct-2 | 2.5x | 3.5x |
+ | Unmarshal/SimpleDocument/map-2 | 4.3x | 3.5x |
+ | Unmarshal/SimpleDocument/struct-2 | 5.9x | 4.5x |
+ | UnmarshalDataset/example-2 | 3.2x | 2.9x |
+ | UnmarshalDataset/code-2 | 2.4x | 2.9x |
+ | UnmarshalDataset/twitter-2 | 2.7x | 2.5x |
+ | UnmarshalDataset/citm_catalog-2 | 2.1x | 2.1x |
+ | UnmarshalDataset/canada-2 | 1.9x | 1.5x |
+ | UnmarshalDataset/config-2 | 5.4x | 3.1x |
+ | geomean | 2.9x | 2.8x |
This table can be generated with ./ci.sh benchmark -a -html.
diff --git a/ci.sh b/ci.sh
index 86217a9..30c23d1 100755
--- a/ci.sh
+++ b/ci.sh
@@ -147,7 +147,7 @@ bench() {
pushd "$dir"
if [ "${replace}" != "" ]; then
- find ./benchmark/ -iname '*.go' -exec sed -i -E "s|github.com/pelletier/go-toml/v2|${replace}|g" {} \;
+ find ./benchmark/ -iname '*.go' -exec sed -i -E "s|github.com/pelletier/go-toml/v2\"|${replace}\"|g" {} \;
go get "${replace}"
fi
@@ -195,6 +195,11 @@ for line in reversed(lines[2:]):
"%.1fx" % (float(line[3])/v2), # v1
"%.1fx" % (float(line[7])/v2), # bs
])
+
+if not results:
+ print("No benchmark results to display.", file=sys.stderr)
+ sys.exit(1)
+
# move geomean to the end
results.append(results[0])
del results[0]