summaryrefslogtreecommitdiff
path: root/tests/benchmarks/string-roundtrip/uuid.go
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2025-05-03 19:41:19 -0300
committerEuAndreh <eu@euandre.org>2025-05-03 19:41:19 -0300
commita6e6896309007fa1013bd51cee125ab8a75f282d (patch)
treef6839c339e9d282138a793488cd8ac23ca356ac6 /tests/benchmarks/string-roundtrip/uuid.go
parenttests/guuid.go: Use os.Exit over assert when testing panic (diff)
downloaduuid-a6e6896309007fa1013bd51cee125ab8a75f282d.tar.gz
uuid-a6e6896309007fa1013bd51cee125ab8a75f282d.tar.xz
re s/guuid/uuid/g
Diffstat (limited to 'tests/benchmarks/string-roundtrip/uuid.go')
-rw-r--r--tests/benchmarks/string-roundtrip/uuid.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/benchmarks/string-roundtrip/uuid.go b/tests/benchmarks/string-roundtrip/uuid.go
new file mode 100644
index 0000000..d686e04
--- /dev/null
+++ b/tests/benchmarks/string-roundtrip/uuid.go
@@ -0,0 +1,37 @@
+package uuid
+
+import (
+ "flag"
+ "fmt"
+)
+
+
+
+var nFlag = flag.Int(
+ "n",
+ 10_000_000,
+ "The number of iterations to execute",
+)
+
+func MainTest() {
+ flag.Parse()
+ n := *nFlag
+
+ uuid := New()
+
+ for i := 0; i < n; i++ {
+ derived, err := FromString(uuid.String())
+ if err != nil {
+ panic(err)
+ }
+
+ eq := uuid == derived
+ if !eq {
+ panic(fmt.Sprintf(
+ "bad round trip: orig (%#v); derived (%#v)",
+ uuid,
+ derived,
+ ))
+ }
+ }
+}