The base solution is adapted from: https://stackoverflow.com/a/5222365/ beat it up!
x <- sample(1e6) microbenchmark::microbenchmark( cumsum(c(1L, diff(x) != 1L)), mmy::group_consecutive(x), check = "identical" )
early_exit
optionmicrobenchmark::microbenchmark( with_early_exit = mmy::group_consecutive(x), without_early_exit = mmy::group_consecutive(x, .early_exit = FALSE), check = "identical" )
Seems that early_exit
does not affect performance in mixed samples.
What about consecutive numbers?
y <- seq(1e6) microbenchmark::microbenchmark( with_early_exit = mmy::group_consecutive(y), without_early_exit = mmy::group_consecutive(y, .early_exit = FALSE), check = "identical" )
Seems that the early exit is slightly faster than the without early_exit
but don't
know whether the difference is significant.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.