carbon/setter_bench_test.go

213 lines
3.7 KiB
Go
Raw Normal View History

2023-12-28 11:27:27 +08:00
package carbon
import (
"testing"
"time"
)
2024-01-12 10:57:10 +08:00
func BenchmarkCarbon_SetWeekStartsAt(b *testing.B) {
for n := 0; n < b.N; n++ {
SetWeekStartsAt(Sunday)
}
c := NewCarbon()
for n := 0; n < b.N; n++ {
c.SetWeekStartsAt(Sunday)
}
}
2023-12-28 11:27:27 +08:00
func BenchmarkCarbon_SetTimezone(b *testing.B) {
for n := 0; n < b.N; n++ {
SetTimezone(PRC)
}
2024-01-12 10:57:10 +08:00
c := NewCarbon()
for n := 0; n < b.N; n++ {
c.SetTimezone(PRC)
}
2023-12-28 11:27:27 +08:00
}
func BenchmarkCarbon_SetLocation(b *testing.B) {
loc, _ := time.LoadLocation(PRC)
for n := 0; n < b.N; n++ {
SetLocation(loc)
}
2024-01-12 10:57:10 +08:00
c := NewCarbon()
for n := 0; n < b.N; n++ {
c.SetLocation(loc)
}
2023-12-28 11:27:27 +08:00
}
func BenchmarkCarbon_SetLocale(b *testing.B) {
for n := 0; n < b.N; n++ {
SetLocale("en")
}
2024-01-12 10:57:10 +08:00
c := NewCarbon()
2023-12-28 11:27:27 +08:00
for n := 0; n < b.N; n++ {
2024-01-12 10:57:10 +08:00
c.SetLocale("en")
2023-12-28 11:27:27 +08:00
}
}
func BenchmarkCarbon_SetDateTime(b *testing.B) {
2024-01-12 10:57:10 +08:00
c := NewCarbon()
2023-12-28 11:27:27 +08:00
for n := 0; n < b.N; n++ {
2024-01-12 10:57:10 +08:00
c.SetDateTime(2020, 8, 5, 0, 0, 0)
2023-12-28 11:27:27 +08:00
}
}
func BenchmarkCarbon_SetDateTimeMilli(b *testing.B) {
2024-01-12 10:57:10 +08:00
c := NewCarbon()
2023-12-28 11:27:27 +08:00
for n := 0; n < b.N; n++ {
2024-01-12 10:57:10 +08:00
c.SetDateTimeMilli(2020, 8, 5, 0, 0, 0, 0)
2023-12-28 11:27:27 +08:00
}
}
func BenchmarkCarbon_SetDateTimeMicro(b *testing.B) {
2024-01-12 10:57:10 +08:00
c := NewCarbon()
2023-12-28 11:27:27 +08:00
for n := 0; n < b.N; n++ {
2024-01-12 10:57:10 +08:00
c.SetDateTimeMicro(2020, 8, 5, 0, 0, 0, 0)
2023-12-28 11:27:27 +08:00
}
}
func BenchmarkCarbon_SetDateTimeNano(b *testing.B) {
2024-01-12 10:57:10 +08:00
c := NewCarbon()
2023-12-28 11:27:27 +08:00
for n := 0; n < b.N; n++ {
2024-01-12 10:57:10 +08:00
c.SetDateTimeNano(2020, 8, 5, 0, 0, 0, 0)
2023-12-28 11:27:27 +08:00
}
}
func BenchmarkCarbon_SetDate(b *testing.B) {
2024-01-12 10:57:10 +08:00
c := NewCarbon()
2023-12-28 11:27:27 +08:00
for n := 0; n < b.N; n++ {
2024-01-12 10:57:10 +08:00
c.SetDate(2020, 8, 5)
2023-12-28 11:27:27 +08:00
}
}
func BenchmarkCarbon_SetDateMilli(b *testing.B) {
2024-01-12 10:57:10 +08:00
c := NewCarbon()
2023-12-28 11:27:27 +08:00
for n := 0; n < b.N; n++ {
2024-01-12 10:57:10 +08:00
c.SetDateMilli(2020, 8, 5, 0)
2023-12-28 11:27:27 +08:00
}
}
func BenchmarkCarbon_SetDateMicro(b *testing.B) {
2024-01-12 10:57:10 +08:00
c := NewCarbon()
2023-12-28 11:27:27 +08:00
for n := 0; n < b.N; n++ {
2024-01-12 10:57:10 +08:00
c.SetDateMicro(2020, 8, 5, 0)
2023-12-28 11:27:27 +08:00
}
}
func BenchmarkCarbon_SetDateNano(b *testing.B) {
2024-01-12 10:57:10 +08:00
c := NewCarbon()
2023-12-28 11:27:27 +08:00
for n := 0; n < b.N; n++ {
2024-01-12 10:57:10 +08:00
c.SetDateNano(2020, 8, 5, 0)
2023-12-28 11:27:27 +08:00
}
}
func BenchmarkCarbon_SetTime(b *testing.B) {
2024-01-12 10:57:10 +08:00
c := NewCarbon()
2023-12-28 11:27:27 +08:00
for n := 0; n < b.N; n++ {
2024-01-12 10:57:10 +08:00
c.SetTime(13, 14, 15)
2023-12-28 11:27:27 +08:00
}
}
func BenchmarkCarbon_SetTimeMilli(b *testing.B) {
2024-01-12 10:57:10 +08:00
c := NewCarbon()
2023-12-28 11:27:27 +08:00
for n := 0; n < b.N; n++ {
2024-01-12 10:57:10 +08:00
c.SetTimeMilli(13, 14, 15, 0)
2023-12-28 11:27:27 +08:00
}
}
func BenchmarkCarbon_SetTimeMicro(b *testing.B) {
2024-01-12 10:57:10 +08:00
c := NewCarbon()
2023-12-28 11:27:27 +08:00
for n := 0; n < b.N; n++ {
2024-01-12 10:57:10 +08:00
c.SetTimeMicro(13, 14, 15, 0)
2023-12-28 11:27:27 +08:00
}
}
func BenchmarkCarbon_SetTimeNano(b *testing.B) {
2024-01-12 10:57:10 +08:00
c := NewCarbon()
2023-12-28 11:27:27 +08:00
for n := 0; n < b.N; n++ {
2024-01-12 10:57:10 +08:00
c.SetTimeNano(13, 14, 15, 0)
2023-12-28 11:27:27 +08:00
}
}
func BenchmarkCarbon_SetYear(b *testing.B) {
2024-01-12 10:57:10 +08:00
c := NewCarbon()
2023-12-28 11:27:27 +08:00
for n := 0; n < b.N; n++ {
2024-01-12 10:57:10 +08:00
c.SetYear(2020)
2023-12-28 11:27:27 +08:00
}
}
func BenchmarkCarbon_SetYearNoOverflow(b *testing.B) {
2024-01-12 10:57:10 +08:00
c := NewCarbon()
2023-12-28 11:27:27 +08:00
for n := 0; n < b.N; n++ {
2024-01-12 10:57:10 +08:00
c.SetYearNoOverflow(2020)
2023-12-28 11:27:27 +08:00
}
}
func BenchmarkCarbon_SetMonth(b *testing.B) {
2024-01-12 10:57:10 +08:00
c := NewCarbon()
2023-12-28 11:27:27 +08:00
for n := 0; n < b.N; n++ {
2024-01-12 10:57:10 +08:00
c.SetMonth(8)
2023-12-28 11:27:27 +08:00
}
}
func BenchmarkCarbon_SetMonthNoOverflow(b *testing.B) {
2024-01-12 10:57:10 +08:00
c := NewCarbon()
2023-12-28 11:27:27 +08:00
for n := 0; n < b.N; n++ {
2024-01-12 10:57:10 +08:00
c.SetMonthNoOverflow(8)
2023-12-28 11:27:27 +08:00
}
}
func BenchmarkCarbon_SetDay(b *testing.B) {
2024-01-12 10:57:10 +08:00
c := NewCarbon()
2023-12-28 11:27:27 +08:00
for n := 0; n < b.N; n++ {
2024-01-12 10:57:10 +08:00
c.SetDay(20)
2023-12-28 11:27:27 +08:00
}
}
func BenchmarkCarbon_SetHour(b *testing.B) {
2024-01-12 10:57:10 +08:00
c := NewCarbon()
2023-12-28 11:27:27 +08:00
for n := 0; n < b.N; n++ {
2024-01-12 10:57:10 +08:00
c.SetHour(20)
2023-12-28 11:27:27 +08:00
}
}
func BenchmarkCarbon_SetMinute(b *testing.B) {
2024-01-12 10:57:10 +08:00
c := NewCarbon()
2023-12-28 11:27:27 +08:00
for n := 0; n < b.N; n++ {
2024-01-12 10:57:10 +08:00
c.SetMinute(20)
2023-12-28 11:27:27 +08:00
}
}
func BenchmarkCarbon_SetSecond(b *testing.B) {
2024-01-12 10:57:10 +08:00
c := NewCarbon()
2023-12-28 11:27:27 +08:00
for n := 0; n < b.N; n++ {
2024-01-12 10:57:10 +08:00
c.SetSecond(20)
2023-12-28 11:27:27 +08:00
}
}
func BenchmarkCarbon_SetMillisecond(b *testing.B) {
2024-01-12 10:57:10 +08:00
c := NewCarbon()
2023-12-28 11:27:27 +08:00
for n := 0; n < b.N; n++ {
2024-01-12 10:57:10 +08:00
c.SetMillisecond(20)
2023-12-28 11:27:27 +08:00
}
}
func BenchmarkCarbon_SetMicrosecond(b *testing.B) {
2024-01-12 10:57:10 +08:00
c := NewCarbon()
2023-12-28 11:27:27 +08:00
for n := 0; n < b.N; n++ {
2024-01-12 10:57:10 +08:00
c.SetMicrosecond(20)
2023-12-28 11:27:27 +08:00
}
}
func BenchmarkCarbon_SetNanosecond(b *testing.B) {
2024-01-12 10:57:10 +08:00
c := NewCarbon()
2023-12-28 11:27:27 +08:00
for n := 0; n < b.N; n++ {
2024-01-12 10:57:10 +08:00
c.SetNanosecond(20)
2023-12-28 11:27:27 +08:00
}
}