Get year, month, day via a single call to time.Time.Date and hour, minute, seconds via time.Time.Clock. This change eliminates multiple calls to time.Time.date and time.Time.abs.
Don't allocate new time.Time if desired location is UTC.
Benchmark results of getTimeWithDifferentLocation:
name old time/op new time/op delta
GetTimeWithDifferentLocation-32 32.8ns ± 3% 17.4ns ± 3% -46.83% (p=0.000 n=10+10)
name old alloc/op new alloc/op delta
GetTimeWithDifferentLocation-32 0.00B 0.00B ~ (all equal)
name old allocs/op new allocs/op delta
GetTimeWithDifferentLocation-32 0.00 0.00 ~ (all equal)
Summary
time.Time.Date
and hour, minute, seconds viatime.Time.Clock
. This change eliminates multiple calls totime.Time.date
andtime.Time.abs
.time.Time
if desired location isUTC
.Benchmark results of
getTimeWithDifferentLocation
:Raw benchmark results
**Old version** ```go // "old" version func getTimeWithDifferentLocation(t time.Time, loc *time.Location) time.Time { return time.Date(t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second(), t.Nanosecond(), loc) } ``` ``` goos: linux goarch: amd64 pkg: github.com/ClickHouse/clickhouse-go/v2/lib/column cpu: 13th Gen Intel(R) Core(TM) i9-13900HX BenchmarkGetTimeWithDifferentLocation BenchmarkGetTimeWithDifferentLocation-32 36481345 33.37 ns/op 0 B/op 0 allocs/op BenchmarkGetTimeWithDifferentLocation-32 33599790 32.63 ns/op 0 B/op 0 allocs/op BenchmarkGetTimeWithDifferentLocation-32 38609709 33.81 ns/op 0 B/op 0 allocs/op BenchmarkGetTimeWithDifferentLocation-32 37585620 32.85 ns/op 0 B/op 0 allocs/op BenchmarkGetTimeWithDifferentLocation-32 38654622 32.43 ns/op 0 B/op 0 allocs/op BenchmarkGetTimeWithDifferentLocation-32 37217412 33.23 ns/op 0 B/op 0 allocs/op BenchmarkGetTimeWithDifferentLocation-32 34944349 32.15 ns/op 0 B/op 0 allocs/op BenchmarkGetTimeWithDifferentLocation-32 37236122 32.88 ns/op 0 B/op 0 allocs/op BenchmarkGetTimeWithDifferentLocation-32 38284749 32.53 ns/op 0 B/op 0 allocs/op BenchmarkGetTimeWithDifferentLocation-32 36064225 32.32 ns/op 0 B/op 0 allocs/op PASS ok github.com/ClickHouse/clickhouse-go/v2/lib/column 12.454s ``` **Optimized version** ``` goos: linux goarch: amd64 pkg: github.com/ClickHouse/clickhouse-go/v2/lib/column cpu: 13th Gen Intel(R) Core(TM) i9-13900HX BenchmarkGetTimeWithDifferentLocation BenchmarkGetTimeWithDifferentLocation-32 73176572 17.92 ns/op 0 B/op 0 allocs/op BenchmarkGetTimeWithDifferentLocation-32 63622671 17.43 ns/op 0 B/op 0 allocs/op BenchmarkGetTimeWithDifferentLocation-32 73126280 17.48 ns/op 0 B/op 0 allocs/op BenchmarkGetTimeWithDifferentLocation-32 69986809 17.41 ns/op 0 B/op 0 allocs/op BenchmarkGetTimeWithDifferentLocation-32 69220406 17.56 ns/op 0 B/op 0 allocs/op BenchmarkGetTimeWithDifferentLocation-32 70910238 17.39 ns/op 0 B/op 0 allocs/op BenchmarkGetTimeWithDifferentLocation-32 71086362 17.63 ns/op 0 B/op 0 allocs/op BenchmarkGetTimeWithDifferentLocation-32 72798584 17.16 ns/op 0 B/op 0 allocs/op BenchmarkGetTimeWithDifferentLocation-32 68707909 17.33 ns/op 0 B/op 0 allocs/op BenchmarkGetTimeWithDifferentLocation-32 65608513 17.19 ns/op 0 B/op 0 allocs/op PASS ok github.com/ClickHouse/clickhouse-go/v2/lib/column 12.387s ```Checklist
Delete items not relevant to your PR: