Skip to content

Commit

Permalink
fix median calculation for missing data in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Tofel committed Dec 13, 2024
1 parent 5a1c3e7 commit 73df456
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 14 deletions.
12 changes: 7 additions & 5 deletions book/src/libs/wasp/benchspy/loki_std.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,13 @@ var compareMedian = func(metricName string) {
previousMedian := benchspy.CalculatePercentile(previousFloatSlice, 0.5)

var diffPercentage float64
if previousMedian != 0 {
diffPercentage = (currentMedian - previousMedian) / previousMedian * 100
} else {
diffPercentage = 100
}
if previousMedian != 0.0 && currentMedian != 0.0 {
diffPrecentage = (currentMedian - previousMedian) / previousMedian * 100
} else if previousMedian == 0.0 && currentMedian == 0.0 {
diffPrecentage = 0.0
} else {
diffPrecentage = 100.0
}
assert.LessOrEqual(t, math.Abs(diffPercentage), 1.0, "%s medians are more than 1% different", metricName, fmt.Sprintf("%.4f", diffPercentage))
}

Expand Down
8 changes: 5 additions & 3 deletions book/src/libs/wasp/benchspy/simplest_metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ var compareValues = func(
previousMetric := previousAsFloat64[metricName]

var diffPercentage float64
if previousMetric != 0.0 {
diffPercentage = (currentMetric - previousMetric) / previousMetric * 100
if previousMetric != 0.0 && currentMetric != 0.0 {
diffPrecentage = (currentMetric - previousMetric) / previousMetric * 100
} else if previousMetric == 0.0 && currentMetric == 0.0 {
diffPrecentage = 0.0
} else {
diffPercentage = 100.0
diffPrecentage = 100.0
}
assert.LessOrEqual(t, math.Abs(diffPercentage), maxDiffPercentage, "%s medians are more than 1% different", metricName, fmt.Sprintf("%.4f", diffPercentage))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,14 @@ func TestBenchSpy_Standard_Direct_Metrics(t *testing.T) {
previousMetric := previousAsloat64[metricName]

var diffPrecentage float64
if previousMetric != 0.0 {
if previousMetric != 0.0 && currentMetric != 0.0 {
diffPrecentage = (currentMetric - previousMetric) / previousMetric * 100
} else if previousMetric == 0.0 && currentMetric == 0.0 {
diffPrecentage = 0.0
} else {
diffPrecentage = 100.0
}
assert.LessOrEqual(t, math.Abs(diffPrecentage), maxDiffPercentage, "%s medians are more than 1% different", metricName, fmt.Sprintf("%.4f", diffPrecentage))
assert.LessOrEqual(t, math.Abs(diffPrecentage), maxDiffPercentage, "%s medians are more than %f different", metricName, fmt.Sprintf("%.4f", diffPrecentage))
}

compareValues(string(benchspy.MedianLatency), 1.0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,12 @@ var compareMedian = func(t *testing.T, metricName string, currentAsStringSlice,
previousMedian := benchspy.CalculatePercentile(previousFloatSlice, 0.5)

var diffPrecentage float64
if previousMedian != 0 {
if previousMedian != 0.0 && currentMedian != 0.0 {
diffPrecentage = (currentMedian - previousMedian) / previousMedian * 100
} else if previousMedian == 0.0 && currentMedian == 0.0 {
diffPrecentage = 0.0
} else {
diffPrecentage = 100
diffPrecentage = 100.0
}
assert.LessOrEqual(t, math.Abs(diffPrecentage), 1.0, "%s medians are more than 1% different", metricName, fmt.Sprintf("%.4f", diffPrecentage))
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,12 @@ var compareMedian = func(t *testing.T, metricName string, currentAsStringSlice,
previousMedian := benchspy.CalculatePercentile(previousFloatSlice, 0.5)

var diffPrecentage float64
if previousMedian != 0 {
if previousMedian != 0.0 && currentMedian != 0.0 {
diffPrecentage = (currentMedian - previousMedian) / previousMedian * 100
} else if previousMedian == 0.0 && currentMedian == 0.0 {
diffPrecentage = 0.0
} else {
diffPrecentage = currentMedian * 100
diffPrecentage = 100.0
}
assert.LessOrEqual(t, math.Abs(diffPrecentage), 1.0, "%s medians are more than 1% different", metricName, fmt.Sprintf("%.4f", diffPrecentage))
}

0 comments on commit 73df456

Please sign in to comment.