Time - Core helpers
This page lists all time operations available in the core package of lo.
Help improve this documentation
This documentation is still new and evolving. If you spot any mistakes, unclear explanations, or missing details, please open an issue.
Your feedback helps us improve!
DurationXโ
Measures execution time of a function. Variants return the elapsed duration alongside 0 to 10 returned values from the function.
// Base variant (no return values): DurationelapsedOnly := lo.Duration(func() {time.Sleep(3 * time.Millisecond)})_ = elapsedOnly// Zero-return variant: Duration0elapsed := lo.Duration0(func() {time.Sleep(10 * time.Millisecond)})_ = elapsed// One-return variant: Duration1v, dur := lo.Duration1(func() int {time.Sleep(5 * time.Millisecond)return 123})_ = v_ = dur// Two-return variant: Duration2a, b, elapsed2 := lo.Duration2(func() (int, string) {time.Sleep(2 * time.Millisecond)return 7, "x"})_ = a_ = b_ = elapsed2Variant:Prototypes:func Duration(callback func()) time.Durationfunc Duration0(callback func()) time.Durationfunc Duration1[T any](callback func() T) (T, time.Duration)func Duration2[T, U any](callback func() (T, U)) (T, U, time.Duration)func Duration3[T, U, V any](callback func() (T, U, V)) (T, U, V, time.Duration)func Duration4[T, U, V, W any](callback func() (T, U, V, W)) (T, U, V, W, time.Duration)func Duration5[T, U, V, W, X any](callback func() (T, U, V, W, X)) (T, U, V, W, X, time.Duration)func Duration6[T, U, V, W, X, Y any](callback func() (T, U, V, W, X, Y)) (T, U, V, W, X, Y, time.Duration)func Duration7[T, U, V, W, X, Y, Z any](callback func() (T, U, V, W, X, Y, Z)) (T, U, V, W, X, Y, Z, time.Duration)func Duration8[T, U, V, W, X, Y, Z, A any](callback func() (T, U, V, W, X, Y, Z, A)) (T, U, V, W, X, Y, Z, A, time.Duration)func Duration9[T, U, V, W, X, Y, Z, A, B any](callback func() (T, U, V, W, X, Y, Z, A, B)) (T, U, V, W, X, Y, Z, A, B, time.Duration)func Duration10[T, U, V, W, X, Y, Z, A, B, C any](callback func() (T, U, V, W, X, Y, Z, A, B, C)) (T, U, V, W, X, Y, Z, A, B, C, time.Duration)