diff options
author | Giuliano Belinassi <giuliano.belinassi@usp.br> | 2020-08-22 17:43:43 -0300 |
---|---|---|
committer | Giuliano Belinassi <giuliano.belinassi@usp.br> | 2020-08-22 17:43:43 -0300 |
commit | a926878ddbd5a98b272c22171ce58663fc04c3e0 (patch) | |
tree | 86af256e5d9a9c06263c00adc90e5fe348008c43 /libgo/go/time/tick_test.go | |
parent | 542730f087133690b47e036dfd43eb0db8a650ce (diff) | |
parent | 07cbaed8ba7d1b6e4ab3a9f44175502a4e1ecdb1 (diff) | |
download | gcc-devel/autopar_devel.zip gcc-devel/autopar_devel.tar.gz gcc-devel/autopar_devel.tar.bz2 |
Merge branch 'autopar_rebase2' into autopar_develdevel/autopar_devel
Quickly commit changes in the rebase branch.
Diffstat (limited to 'libgo/go/time/tick_test.go')
-rw-r--r-- | libgo/go/time/tick_test.go | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/libgo/go/time/tick_test.go b/libgo/go/time/tick_test.go index 71ea367..c0c6e76 100644 --- a/libgo/go/time/tick_test.go +++ b/libgo/go/time/tick_test.go @@ -22,7 +22,12 @@ func TestTicker(t *testing.T) { // On Darwin ARM64 the tick frequency seems limited. Issue 35692. if runtime.GOOS == "darwin" && runtime.GOARCH == "arm64" { - count = 5 + // The following test will run ticker count/2 times then reset + // the ticker to double the duration for the rest of count/2. + // Since tick frequency is limited on Darwin ARM64, use even + // number to give the ticks more time to let the test pass. + // See CL 220638. + count = 6 delta = 100 * Millisecond } @@ -36,13 +41,17 @@ func TestTicker(t *testing.T) { for i := 0; i < 5; i++ { ticker := NewTicker(delta) t0 := Now() - for i := 0; i < count; i++ { + for i := 0; i < count/2; i++ { + <-ticker.C + } + ticker.Reset(delta * 2) + for i := count / 2; i < count; i++ { <-ticker.C } ticker.Stop() t1 := Now() dt := t1.Sub(t0) - target := delta * Duration(count) + target := 3 * delta * Duration(count/2) slop := target * 2 / 10 if dt < target-slop || dt > target+slop { errs = append(errs, fmt.Sprintf("%d %s ticks took %s, expected [%s,%s]", count, delta, dt, target-slop, target+slop)) @@ -118,3 +127,24 @@ func BenchmarkTicker(b *testing.B) { ticker.Stop() }) } + +func BenchmarkTickerReset(b *testing.B) { + benchmark(b, func(n int) { + ticker := NewTicker(Nanosecond) + for i := 0; i < n; i++ { + ticker.Reset(Nanosecond * 2) + } + ticker.Stop() + }) +} + +func BenchmarkTickerResetNaive(b *testing.B) { + benchmark(b, func(n int) { + ticker := NewTicker(Nanosecond) + for i := 0; i < n; i++ { + ticker.Stop() + ticker = NewTicker(Nanosecond * 2) + } + ticker.Stop() + }) +} |