Skip to content

Commit

Permalink
Don't recalculate values in loop
Browse files Browse the repository at this point in the history
This doesn't affect performance on M1 but has 3-5% improvement on x86_64.
  • Loading branch information
MaXal committed Nov 15, 2023
1 parent cf10510 commit 6defdb6
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pkg/degradation-detector/changeDetector.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,15 @@ func getPartialSums(data []int, k int) [][]int {

func getSegmentCost(partialSums [][]int, tau1, tau2, k, n int) float64 {
var sum float64
tauDiff := float64(tau2 - tau1)
tauDiffDoubled := (tau2 - tau1) * 2
for i := 0; i < k; i++ {
// actualSum is (count(data[j] < t) * 2 + count(data[j] == t) * 1) for j=tau1..tau2-1
actualSum := partialSums[i][tau2] - partialSums[i][tau1]

if actualSum != 0 && actualSum != (tau2-tau1)*2 {
fit := float64(actualSum) / float64((tau2-tau1)*2)
lnp := float64(tau2-tau1) * (fit*math.Log(fit) + (1-fit)*math.Log1p(-fit))
if actualSum != 0 && actualSum != tauDiffDoubled {
fit := float64(actualSum) / float64(tauDiffDoubled)
lnp := tauDiff * (fit*math.Log(fit) + (1-fit)*math.Log1p(-fit))
sum += lnp
}
}
Expand Down

0 comments on commit 6defdb6

Please sign in to comment.