Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small performance improvement #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

s-Nick-s
Copy link

@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