mirror of
https://github.com/samber/lo.git
synced 2026-04-22 15:37:14 +08:00
fa095e4b4f
* fix(doc): fix go playground demo URL * fix(doc): add more go playground demo URL
2.3 KiB
2.3 KiB
name, slug, sourceRef, category, subCategory, signatures, playUrl, variantHelpers, similarHelpers, position
| name | slug | sourceRef | category | subCategory | signatures | playUrl | variantHelpers | similarHelpers | position | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| DurationX | durationx | time.go#L7 | core | time |
|
https://go.dev/play/p/LFhKq2vY9Ty |
|
|
0 |
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): Duration
elapsedOnly := lo.Duration(func() {
time.Sleep(3 * time.Millisecond)
})
_ = elapsedOnly
// Zero-return variant: Duration0
elapsed := lo.Duration0(func() {
time.Sleep(10 * time.Millisecond)
})
_ = elapsed
// One-return variant: Duration1
v, dur := lo.Duration1(func() int {
time.Sleep(5 * time.Millisecond)
return 123
})
_ = v
_ = dur
// Two-return variant: Duration2
a, b, elapsed2 := lo.Duration2(func() (int, string) {
time.Sleep(2 * time.Millisecond)
return 7, "x"
})
_ = a
_ = b
_ = elapsed2