diff --git a/Makefile b/Makefile index 5d30e51..e7cabea 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ test-chart: SHELL:=/bin/bash test-chart: go test & until pidof mumble-discord-bridge.test; do continue; done; - psrecord --plot test-cpu-memory.png $$(pidof mumble-discord-bridge.test) + psrecord --plot docs/test-cpu-memory.png $$(pidof mumble-discord-bridge.test) docker-latest: docker build -t stieneee/mumble-discord-bridge:latest . diff --git a/docs/test-cpu-memory.png b/docs/test-cpu-memory.png index 90a9914..3d20fc2 100644 Binary files a/docs/test-cpu-memory.png and b/docs/test-cpu-memory.png differ diff --git a/test-cpu-memory.png b/test-cpu-memory.png deleted file mode 100644 index 50c4db5..0000000 Binary files a/test-cpu-memory.png and /dev/null differ diff --git a/timing_test.go b/timing_test.go index f0935cc..d6b69b1 100644 --- a/timing_test.go +++ b/timing_test.go @@ -2,7 +2,9 @@ package main import ( "fmt" + "math" "math/rand" + "sort" "sync" "testing" "time" @@ -100,3 +102,40 @@ func TestSleepCT(t *testing.T) { wg.Wait() } + +func TestIdleJitter(t *testing.T) { + wg := sync.WaitGroup{} + + const testSize = 100000 + const sleepTarget = time.Millisecond + + res := make([]time.Duration, testSize) + + for i := 0; i < testSize; i++ { + start := time.Now() + target := start.Add(sleepTarget) + + time.Sleep(sleepTarget) + + res[i] = time.Since(target) + } + + sort.Slice(res, func(i, j int) bool { + return res[i] < res[j] + }) + + var total float64 = 0 + for i := 0; i < testSize; i++ { + total += float64(res[i]) + } + avg := time.Duration(total / testSize) + + nineFive := int64(math.Round(testSize * 0.95)) + nineNine := int64(math.Round(testSize * 0.99)) + nineNineNine := int64(math.Round(testSize * 0.999)) + + fmt.Println("IdleJitter test", testSize, sleepTarget) + fmt.Println("IdleJitter results min/avg/95/99/99.9/max", res[0], avg, res[nineFive], res[nineNine], res[nineNineNine], res[testSize-1]) + + wg.Wait() +}