summaryrefslogtreecommitdiffstats
path: root/snowflake_bench_test.go
diff options
context:
space:
mode:
authorEthan Werner <mail@ethanwerner.com>2026-06-30 00:29:48 +0400
committerEthan Werner <mail@ethanwerner.com>2026-06-30 04:43:45 +0400
commit13d844c130b7d55c8c598842de59391d9c66bc67 (patch)
tree5db229889ce64e2aeb3f26ec7660a776672f2618 /snowflake_bench_test.go
initial commit
Diffstat (limited to 'snowflake_bench_test.go')
-rw-r--r--snowflake_bench_test.go69
1 files changed, 69 insertions, 0 deletions
diff --git a/snowflake_bench_test.go b/snowflake_bench_test.go
new file mode 100644
index 0000000..e630f19
--- /dev/null
+++ b/snowflake_bench_test.go
@@ -0,0 +1,69 @@
+package snowflake
+
+import "testing"
+
+var benchmarkSnowflake Snowflake
+
+func init() {
+ benchmarkSnowflake, _ = New()
+}
+
+func BenchmarkNew(b *testing.B) {
+ b.ReportAllocs()
+ for i := 0; i < b.N; i++ {
+ New()
+ }
+}
+
+func BenchmarkSnowflake_String(b *testing.B) {
+ b.ReportAllocs()
+ for i := 0; i < b.N; i++ {
+ benchmarkSnowflake.String()
+ }
+}
+
+func BenchmarkFromString(b *testing.B) {
+ s := benchmarkSnowflake.String()
+ b.ReportAllocs()
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ FromString(s)
+ }
+}
+
+func BenchmarkSnowflake_Hex(b *testing.B) {
+ b.ReportAllocs()
+ for i := 0; i < b.N; i++ {
+ benchmarkSnowflake.Hex()
+ }
+}
+
+func BenchmarkFromHex(b *testing.B) {
+ h := benchmarkSnowflake.Hex()
+ b.ReportAllocs()
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ FromHex(h)
+ }
+}
+
+func BenchmarkMarshalJSON(b *testing.B) {
+ b.ReportAllocs()
+ for i := 0; i < b.N; i++ {
+ benchmarkSnowflake.MarshalJSON()
+ }
+}
+
+func BenchmarkMarshalText(b *testing.B) {
+ b.ReportAllocs()
+ for i := 0; i < b.N; i++ {
+ benchmarkSnowflake.MarshalText()
+ }
+}
+
+func BenchmarkValue(b *testing.B) {
+ b.ReportAllocs()
+ for i := 0; i < b.N; i++ {
+ benchmarkSnowflake.Value()
+ }
+}