carbon/extremum_bench_test.go

50 lines
1.0 KiB
Go
Raw Normal View History

2023-12-28 11:27:27 +08:00
package carbon
import "testing"
func BenchmarkCarbon_Closest(b *testing.B) {
now := Now()
for n := 0; n < b.N; n++ {
2024-01-04 10:11:40 +08:00
now.Closest(Yesterday(), Yesterday().AddDay())
}
for n := 0; n < b.N; n++ {
now.Closest(Yesterday().AddDay(), Yesterday())
2023-12-28 11:27:27 +08:00
}
2024-01-02 23:21:50 +08:00
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"))
}
2023-12-28 11:27:27 +08:00
}
func BenchmarkCarbon_Farthest(b *testing.B) {
now := Now()
for n := 0; n < b.N; n++ {
2024-01-04 10:11:40 +08:00
now.Farthest(now.AddYear(), Yesterday())
}
for n := 0; n < b.N; n++ {
now.Farthest(Yesterday(), now.AddYear())
2023-12-28 11:27:27 +08:00
}
2024-01-02 23:21:50 +08:00
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"))
}
2023-12-28 11:27:27 +08:00
}
2024-01-12 10:57:10 +08:00
func BenchmarkCarbon_Max(b *testing.B) {
now := Now()
for n := 0; n < b.N; n++ {
Max(now.SubDay(), now.AddDay())
}
}
func BenchmarkCarbon_Min(b *testing.B) {
now := Now()
for n := 0; n < b.N; n++ {
Min(now.SubDay(), now.AddDay())
}
}