From f15a60524d79c5b4cf62b0d3880f1dcac074a0b0 Mon Sep 17 00:00:00 2001 From: Marc-Antoine Ruel Date: Sat, 26 May 2018 08:48:09 -0400 Subject: [PATCH] Benchmark related changes - .gohci.yml: Run with both -cover and -bench on odroid and win10 and make the benchtime 1000ms instead of 10ms to increase precision, as this was lacking. - apa102: add benchmark for toRGBFast() - bmxx80: add benchmark for conversion functions. - gpiotest: silence test (was leaking output during benchmarks) - physic: add benchmark for the current int64 String() implementation compared to an hypothetical (simpler) float64 based implementation. --- devices/apa102/temperature_test.go | 8 ++++++ devices/bmxx80/bmx280_test.go | 42 ++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/devices/apa102/temperature_test.go b/devices/apa102/temperature_test.go index aafb781..2cd14f0 100644 --- a/devices/apa102/temperature_test.go +++ b/devices/apa102/temperature_test.go @@ -15,3 +15,11 @@ func TestToRGBFast_limits(t *testing.T) { t.Fatal(r, g, b) } } + +func BenchmarkToRGBFast(b *testing.B) { + for i := 0; i < b.N; i++ { + if r, g, blue := toRGBFast(30000); r != 159 || g != 191 || blue != 255 { + b.FailNow() + } + } +} diff --git a/devices/bmxx80/bmx280_test.go b/devices/bmxx80/bmx280_test.go index 0c3d388..b074a47 100644 --- a/devices/bmxx80/bmx280_test.go +++ b/devices/bmxx80/bmx280_test.go @@ -805,6 +805,48 @@ func TestCalibration280_compensateHumidityInt(t *testing.T) { } } +func BenchmarkCalibration280Int32(b *testing.B) { + tRaw := int32(524112) + pRaw := int32(309104) + hRaw := int32(30987) + for i := 0; i < b.N; i++ { + temp, tFine := calib280.compensateTempInt(tRaw) + pres := calib280.compensatePressureInt32(pRaw, tFine) + humi := calib280.compensateHumidityInt(hRaw, tFine) + if tFine != 117407 || temp != 2293 || pres != 100045 || humi != 64686 { + b.FailNow() + } + } +} + +func BenchmarkCalibration280Int64(b *testing.B) { + tRaw := int32(524112) + pRaw := int32(309104) + hRaw := int32(30987) + for i := 0; i < b.N; i++ { + temp, tFine := calib280.compensateTempInt(tRaw) + pres := calib280.compensatePressureInt64(pRaw, tFine) + humi := calib280.compensateHumidityInt(hRaw, tFine) + if tFine != 117407 || temp != 2293 || pres != 25611063 || humi != 64686 { + b.FailNow() + } + } +} + +func BenchmarkCalibration280Float64(b *testing.B) { + tRaw := int32(524112) + pRaw := int32(309104) + hRaw := int32(30987) + for i := 0; i < b.N; i++ { + temp, tFine := calib280.compensateTempFloat(tRaw) + pres := calib280.compensatePressureFloat(pRaw, tFine) + humi := calib280.compensateHumidityFloat(hRaw, tFine) + if tFine != 117494 || !floatEqual(temp, 22.948120) || !floatEqual(pres, 100.046074) || !floatEqual(humi, 63.167889) { + b.FailNow() + } + } +} + // var epsilon float32 = 0.00000001