-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e5dbef1
commit e367a3c
Showing
11 changed files
with
393 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package bench_test | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/xybor-x/enum" | ||
"github.com/xybor-x/enum/bench" | ||
) | ||
|
||
func BenchmarkGen10ToString(b *testing.B) { | ||
b.Run("Gen", func(b *testing.B) { | ||
enum := bench.GenEnumTypeT9 | ||
for i := 0; i < b.N; i++ { | ||
_ = enum.String() | ||
} | ||
}) | ||
|
||
b.Run("XyborX", func(b *testing.B) { | ||
enum := bench.XyborEnumTypeT9 | ||
for i := 0; i < b.N; i++ { | ||
_ = enum.String() | ||
} | ||
}) | ||
} | ||
|
||
func BenchmarkGen10FromString(b *testing.B) { | ||
b.Run("Gen", func(b *testing.B) { | ||
for i := 0; i < b.N; i++ { | ||
bench.ParseGenEnumType("t9") | ||
} | ||
}) | ||
|
||
b.Run("XyborX", func(b *testing.B) { | ||
for i := 0; i < b.N; i++ { | ||
enum.FromString[bench.XyborEnumType]("t9") | ||
} | ||
}) | ||
} | ||
|
||
func BenchmarkGen10JsonMarshal(b *testing.B) { | ||
b.Run("Gen", func(b *testing.B) { | ||
enum := bench.GenEnumTypeT9 | ||
for i := 0; i < b.N; i++ { | ||
json.Marshal(enum) | ||
} | ||
}) | ||
|
||
b.Run("XyborX", func(b *testing.B) { | ||
enum := bench.XyborEnumTypeT9 | ||
for i := 0; i < b.N; i++ { | ||
json.Marshal(enum) | ||
} | ||
}) | ||
} | ||
|
||
func BenchmarkGen10JsonUnmarshal(b *testing.B) { | ||
b.Run("Gen", func(b *testing.B) { | ||
var enum bench.GenEnumType | ||
for i := 0; i < b.N; i++ { | ||
json.Unmarshal([]byte(`"t9"`), &enum) | ||
} | ||
}) | ||
|
||
b.Run("XyborX", func(b *testing.B) { | ||
var enum bench.XyborEnumType | ||
for i := 0; i < b.N; i++ { | ||
json.Unmarshal([]byte(`"t9"`), &enum) | ||
} | ||
}) | ||
} | ||
|
||
func BenchmarkGen10SqlValue(b *testing.B) { | ||
b.Run("Gen", func(b *testing.B) { | ||
enum := bench.GenEnumTypeT9 | ||
for i := 0; i < b.N; i++ { | ||
enum.Value() | ||
} | ||
}) | ||
|
||
b.Run("XyborX", func(b *testing.B) { | ||
enum := bench.XyborEnumTypeT9 | ||
for i := 0; i < b.N; i++ { | ||
enum.Value() | ||
} | ||
}) | ||
} | ||
|
||
func BenchmarkGen10SqlScanByte(b *testing.B) { | ||
b.Run("Gen", func(b *testing.B) { | ||
var enum bench.GenEnumType | ||
for i := 0; i < b.N; i++ { | ||
enum.Scan([]byte(`t9`)) | ||
} | ||
}) | ||
|
||
b.Run("XyborX", func(b *testing.B) { | ||
var enum bench.XyborEnumType | ||
for i := 0; i < b.N; i++ { | ||
enum.Scan([]byte(`t9`)) | ||
} | ||
}) | ||
} | ||
|
||
func BenchmarkSqlScanString(b *testing.B) { | ||
b.Run("Gen", func(b *testing.B) { | ||
var enum bench.GenEnumType | ||
for i := 0; i < b.N; i++ { | ||
enum.Scan("t9") | ||
} | ||
}) | ||
|
||
b.Run("XyborX", func(b *testing.B) { | ||
var enum bench.XyborEnumType | ||
for i := 0; i < b.N; i++ { | ||
enum.Scan("t9") | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package bench | ||
|
||
//go:generate go-enum --marshal --sql | ||
|
||
// ENUM(t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) | ||
type GenEnumType int |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module github.com/xybor-x/enum/bench | ||
|
||
go 1.22.1 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package bench | ||
|
||
import "github.com/xybor-x/enum" | ||
|
||
type xyborEnumType int | ||
type XyborEnumType = enum.WrapEnum[xyborEnumType] | ||
|
||
const ( | ||
XyborEnumTypeT0 XyborEnumType = iota | ||
XyborEnumTypeT1 | ||
XyborEnumTypeT2 | ||
XyborEnumTypeT3 | ||
XyborEnumTypeT4 | ||
XyborEnumTypeT5 | ||
XyborEnumTypeT6 | ||
XyborEnumTypeT7 | ||
XyborEnumTypeT8 | ||
XyborEnumTypeT9 | ||
) | ||
|
||
var ( | ||
_ = enum.Map(XyborEnumTypeT0, "t0") | ||
_ = enum.Map(XyborEnumTypeT1, "t1") | ||
_ = enum.Map(XyborEnumTypeT2, "t2") | ||
_ = enum.Map(XyborEnumTypeT3, "t3") | ||
_ = enum.Map(XyborEnumTypeT4, "t4") | ||
_ = enum.Map(XyborEnumTypeT5, "t5") | ||
_ = enum.Map(XyborEnumTypeT6, "t6") | ||
_ = enum.Map(XyborEnumTypeT7, "t7") | ||
_ = enum.Map(XyborEnumTypeT8, "t8") | ||
_ = enum.Map(XyborEnumTypeT9, "t9") | ||
) |
Oops, something went wrong.