Skip to content

Small performance improvement#7

Open
s-Nick-s wants to merge 1 commit intohrbrmstr:masterfrom
s-Nick-s:master
Open

Small performance improvement#7
s-Nick-s wants to merge 1 commit intohrbrmstr:masterfrom
s-Nick-s:master

Conversation

@s-Nick-s
Copy link
Copy Markdown

@s-Nick-s s-Nick-s commented Jan 5, 2020

Shrinking data.frames in a loop can be an expensive operation.
This PR replaces data <- data[-which(data[[1L]] == R_idx[i]), ] in detect_anoms with a bool index subsetting.
From my tests this makes ad_ts ~20% faster and slightly more memory efficient.

microbenchmark::microbenchmark(
  out1 <- AnomalyDetection::ad_ts(raw_data, max_anoms=0.1, direction='both'), #before
  out2 <- ad_ts(raw_data, max_anoms=0.1, direction='both') #after
, times = 20)

Unit: seconds
                                                                           expr      min       lq     mean   median       uq      max neval
 out1 <- AnomalyDetection::ad_ts(raw_data, max_anoms = 0.1, direction = "both") 3.936969 4.021261 4.214572 4.066235 4.145791 6.737845    20
                   out2 <- ad_ts(raw_data, max_anoms = 0.1, direction = "both") 3.142772 3.208393 3.394106 3.252814 3.330758 4.446146    20

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant