提高性能测试覆盖率

This commit is contained in:
Peleus 2024-01-04 10:11:40 +08:00
parent 42af04c183
commit 3b1a66176e

View File

@ -5,7 +5,10 @@ import "testing"
func BenchmarkCarbon_Closest(b *testing.B) {
now := Now()
for n := 0; n < b.N; n++ {
now.Closest(Parse("2020-08-05"), Parse("2022-08-05"))
now.Closest(Yesterday(), Yesterday().AddDay())
}
for n := 0; n < b.N; n++ {
now.Closest(Yesterday().AddDay(), Yesterday())
}
for n := 0; n < b.N; n++ {
now.Closest(Parse("xxx"), Parse("2022-08-05"))
@ -18,7 +21,10 @@ func BenchmarkCarbon_Closest(b *testing.B) {
func BenchmarkCarbon_Farthest(b *testing.B) {
now := Now()
for n := 0; n < b.N; n++ {
now.Farthest(Parse("2020-08-05"), Parse("2022-08-05"))
now.Farthest(now.AddYear(), Yesterday())
}
for n := 0; n < b.N; n++ {
now.Farthest(Yesterday(), now.AddYear())
}
for n := 0; n < b.N; n++ {
now.Farthest(Parse("xxx"), Parse("2022-08-05"))