Benchmarks: Use b.Loop() to simplify the code and enhance performance #5226

Signed-off-by: letreturn <letreturn@outlook.com>
This commit is contained in:
letreturn
2025-10-02 23:00:13 +08:00
committed by GitHub
parent 1d984fb8b0
commit c57cacb834
6 changed files with 13 additions and 13 deletions

View File

@@ -20,7 +20,7 @@ func TestAuthToken(t *testing.T) {
}
func BenchmarkAuthToken(b *testing.B) {
for n := 0; n < b.N; n++ {
for b.Loop() {
AuthToken()
}
}
@@ -38,7 +38,7 @@ func TestIsAuthToken(t *testing.T) {
}
func BenchmarkIsAuthToken(b *testing.B) {
for n := 0; n < b.N; n++ {
for b.Loop() {
IsAuthToken("69be27ac5ca305b394046a83f6fda18167ca3d3f2dbe7ac2")
}
}
@@ -52,7 +52,7 @@ func TestAppPassword(t *testing.T) {
}
func BenchmarkAppPassword(b *testing.B) {
for n := 0; n < b.N; n++ {
for b.Loop() {
AppPassword()
}
}
@@ -93,13 +93,13 @@ func TestIsAppPasswordt(t *testing.T) {
}
func BenchmarkAppPasswordtVerifyChecksum(b *testing.B) {
for n := 0; n < b.N; n++ {
for b.Loop() {
IsAppPassword("MPkOqm-RtKGOi-ctIvXm-Qv3XhN", true)
}
}
func BenchmarkAppPasswordIgnoreChecksum(b *testing.B) {
for n := 0; n < b.N; n++ {
for b.Loop() {
IsAppPassword("MPkOqm-RtKGOi-ctIvXm-Qv3XhN", false)
}
}
@@ -166,7 +166,7 @@ func TestIsAuthAny(t *testing.T) {
}
func BenchmarkIsAuthAny(b *testing.B) {
for n := 0; n < b.N; n++ {
for b.Loop() {
IsAuthAny("MPkOqm-RtKGOi-ctIvXm-Qv3XhN")
}
}

View File

@@ -22,7 +22,7 @@ func TestClientSecret(t *testing.T) {
}
func BenchmarkClientSecret(b *testing.B) {
for n := 0; n < b.N; n++ {
for b.Loop() {
ClientSecret()
}
}
@@ -42,7 +42,7 @@ func TestIsClientSecret(t *testing.T) {
}
func BenchmarkIsClientSecret(b *testing.B) {
for n := 0; n < b.N; n++ {
for b.Loop() {
IsClientSecret("69be27ac5ca305b394046a83f6fda181")
}
}

View File

@@ -21,7 +21,7 @@ func TestName(t *testing.T) {
}
func BenchmarkName(b *testing.B) {
for n := 0; n < b.N; n++ {
for b.Loop() {
Name()
}
}

View File

@@ -127,13 +127,13 @@ func TestRandomToken(t *testing.T) {
}
func BenchmarkGenerateToken4(b *testing.B) {
for n := 0; n < b.N; n++ {
for b.Loop() {
Base36(4)
}
}
func BenchmarkGenerateToken3(b *testing.B) {
for n := 0; n < b.N; n++ {
for b.Loop() {
Base36(3)
}
}

View File

@@ -80,7 +80,7 @@ func TestGenerateUID(t *testing.T) {
}
func BenchmarkGenerateUID(b *testing.B) {
for n := 0; n < b.N; n++ {
for b.Loop() {
GenerateUID('x')
}
}

View File

@@ -15,7 +15,7 @@ func TestUUID(t *testing.T) {
}
func BenchmarkUUID(b *testing.B) {
for n := 0; n < b.N; n++ {
for b.Loop() {
UUID()
}
}