v2.3.2 提高性能测试覆盖率

This commit is contained in:
Peleus 2024-01-02 23:21:50 +08:00
parent 2bd45894f8
commit 66732db0cc
3 changed files with 76 additions and 8 deletions

View File

@ -6,6 +6,9 @@ import (
func BenchmarkCarbon_StartOfCentury(b *testing.B) {
now := Now()
for n := 0; n < b.N; n++ {
NewCarbon().StartOfCentury()
}
for n := 0; n < b.N; n++ {
now.StartOfCentury()
}
@ -13,6 +16,9 @@ func BenchmarkCarbon_StartOfCentury(b *testing.B) {
func BenchmarkCarbon_EndOfCentury(b *testing.B) {
now := Now()
for n := 0; n < b.N; n++ {
NewCarbon().EndOfCentury()
}
for n := 0; n < b.N; n++ {
now.EndOfCentury()
}
@ -20,6 +26,9 @@ func BenchmarkCarbon_EndOfCentury(b *testing.B) {
func BenchmarkCarbon_StartOfDecade(b *testing.B) {
now := Now()
for n := 0; n < b.N; n++ {
NewCarbon().StartOfDecade()
}
for n := 0; n < b.N; n++ {
now.StartOfDecade()
}
@ -27,6 +36,9 @@ func BenchmarkCarbon_StartOfDecade(b *testing.B) {
func BenchmarkCarbon_EndOfDecade(b *testing.B) {
now := Now()
for n := 0; n < b.N; n++ {
NewCarbon().EndOfDecade()
}
for n := 0; n < b.N; n++ {
now.EndOfDecade()
}
@ -34,6 +46,9 @@ func BenchmarkCarbon_EndOfDecade(b *testing.B) {
func BenchmarkCarbon_StartOfYear(b *testing.B) {
now := Now()
for n := 0; n < b.N; n++ {
NewCarbon().StartOfYear()
}
for n := 0; n < b.N; n++ {
now.StartOfYear()
}
@ -41,6 +56,9 @@ func BenchmarkCarbon_StartOfYear(b *testing.B) {
func BenchmarkCarbon_EndOfYear(b *testing.B) {
now := Now()
for n := 0; n < b.N; n++ {
NewCarbon().EndOfYear()
}
for n := 0; n < b.N; n++ {
now.EndOfYear()
}
@ -48,6 +66,9 @@ func BenchmarkCarbon_EndOfYear(b *testing.B) {
func BenchmarkCarbon_StartOfQuarter(b *testing.B) {
now := Now()
for n := 0; n < b.N; n++ {
NewCarbon().StartOfQuarter()
}
for n := 0; n < b.N; n++ {
now.StartOfQuarter()
}
@ -55,6 +76,9 @@ func BenchmarkCarbon_StartOfQuarter(b *testing.B) {
func BenchmarkCarbon_EndOfQuarter(b *testing.B) {
now := Now()
for n := 0; n < b.N; n++ {
NewCarbon().EndOfQuarter()
}
for n := 0; n < b.N; n++ {
now.EndOfQuarter()
}
@ -62,6 +86,9 @@ func BenchmarkCarbon_EndOfQuarter(b *testing.B) {
func BenchmarkCarbon_StartOfMonth(b *testing.B) {
now := Now()
for n := 0; n < b.N; n++ {
NewCarbon().StartOfMonth()
}
for n := 0; n < b.N; n++ {
now.StartOfMonth()
}
@ -69,6 +96,9 @@ func BenchmarkCarbon_StartOfMonth(b *testing.B) {
func BenchmarkCarbon_EndOfMonth(b *testing.B) {
now := Now()
for n := 0; n < b.N; n++ {
NewCarbon().EndOfMonth()
}
for n := 0; n < b.N; n++ {
now.EndOfMonth()
}
@ -76,6 +106,9 @@ func BenchmarkCarbon_EndOfMonth(b *testing.B) {
func BenchmarkCarbon_StartOfWeek(b *testing.B) {
now := Now()
for n := 0; n < b.N; n++ {
NewCarbon().StartOfWeek()
}
for n := 0; n < b.N; n++ {
now.StartOfWeek()
}
@ -83,6 +116,9 @@ func BenchmarkCarbon_StartOfWeek(b *testing.B) {
func BenchmarkCarbon_EndOfWeek(b *testing.B) {
now := Now()
for n := 0; n < b.N; n++ {
NewCarbon().EndOfWeek()
}
for n := 0; n < b.N; n++ {
now.EndOfWeek()
}
@ -90,6 +126,9 @@ func BenchmarkCarbon_EndOfWeek(b *testing.B) {
func BenchmarkCarbon_StartOfDay(b *testing.B) {
now := Now()
for n := 0; n < b.N; n++ {
NewCarbon().StartOfDay()
}
for n := 0; n < b.N; n++ {
now.StartOfDay()
}
@ -97,6 +136,9 @@ func BenchmarkCarbon_StartOfDay(b *testing.B) {
func BenchmarkCarbon_EndOfDay(b *testing.B) {
now := Now()
for n := 0; n < b.N; n++ {
NewCarbon().EndOfDay()
}
for n := 0; n < b.N; n++ {
now.EndOfDay()
}
@ -104,6 +146,9 @@ func BenchmarkCarbon_EndOfDay(b *testing.B) {
func BenchmarkCarbon_StartOfHour(b *testing.B) {
now := Now()
for n := 0; n < b.N; n++ {
NewCarbon().StartOfHour()
}
for n := 0; n < b.N; n++ {
now.StartOfHour()
}
@ -111,6 +156,9 @@ func BenchmarkCarbon_StartOfHour(b *testing.B) {
func BenchmarkCarbon_EndOfHour(b *testing.B) {
now := Now()
for n := 0; n < b.N; n++ {
NewCarbon().EndOfHour()
}
for n := 0; n < b.N; n++ {
now.EndOfHour()
}
@ -118,6 +166,9 @@ func BenchmarkCarbon_EndOfHour(b *testing.B) {
func BenchmarkCarbon_StartOfMinute(b *testing.B) {
now := Now()
for n := 0; n < b.N; n++ {
NewCarbon().StartOfMinute()
}
for n := 0; n < b.N; n++ {
now.StartOfMinute()
}
@ -125,6 +176,9 @@ func BenchmarkCarbon_StartOfMinute(b *testing.B) {
func BenchmarkCarbon_EndOfMinute(b *testing.B) {
now := Now()
for n := 0; n < b.N; n++ {
NewCarbon().EndOfMinute()
}
for n := 0; n < b.N; n++ {
now.EndOfMinute()
}
@ -132,6 +186,9 @@ func BenchmarkCarbon_EndOfMinute(b *testing.B) {
func BenchmarkCarbon_StartOfSecond(b *testing.B) {
now := Now()
for n := 0; n < b.N; n++ {
NewCarbon().StartOfSecond()
}
for n := 0; n < b.N; n++ {
now.StartOfSecond()
}
@ -139,6 +196,9 @@ func BenchmarkCarbon_StartOfSecond(b *testing.B) {
func BenchmarkCarbon_EndOfSecond(b *testing.B) {
now := Now()
for n := 0; n < b.N; n++ {
NewCarbon().EndOfSecond()
}
for n := 0; n < b.N; n++ {
now.EndOfSecond()
}

View File

@ -7,6 +7,12 @@ func BenchmarkCarbon_Closest(b *testing.B) {
for n := 0; n < b.N; n++ {
now.Closest(Parse("2020-08-05"), Parse("2022-08-05"))
}
for n := 0; n < b.N; n++ {
now.Closest(Parse("xxx"), Parse("2022-08-05"))
}
for n := 0; n < b.N; n++ {
now.Closest(Parse("2020-08-05"), Parse("xxx"))
}
}
func BenchmarkCarbon_Farthest(b *testing.B) {
@ -14,4 +20,10 @@ func BenchmarkCarbon_Farthest(b *testing.B) {
for n := 0; n < b.N; n++ {
now.Farthest(Parse("2020-08-05"), Parse("2022-08-05"))
}
for n := 0; n < b.N; n++ {
now.Farthest(Parse("xxx"), Parse("2022-08-05"))
}
for n := 0; n < b.N; n++ {
now.Farthest(Parse("2020-08-05"), Parse("xxx"))
}
}

View File

@ -2,17 +2,13 @@ package carbon
import "testing"
func BenchmarkCarbon_Tag(b *testing.B) {
now := Now()
for n := 0; n < b.N; n++ {
now.Tag()
}
}
func BenchmarkCarbon_SetTag(b *testing.B) {
now := Now()
for n := 0; n < b.N; n++ {
now.SetTag("layout:2006-01-02")
now.SetTag(tag{
carbon: "datetime",
tz: Local,
})
}
}