Skip to content

Instantly share code, notes, and snippets.

@abikoushi
Created January 13, 2026 19:10
Show Gist options
  • Select an option

  • Save abikoushi/595ea14e90c733a628fa8fd52802ebc1 to your computer and use it in GitHub Desktop.

Select an option

Save abikoushi/595ea14e90c733a628fa8fd52802ebc1 to your computer and use it in GitHub Desktop.
Try multi-threads `roll` package
library(roll)
library(RcppParallel)
RcppParallel::defaultNumThreads()
x <- rnorm(1e8)
setThreadOptions(numThreads = 1L)
t1 <- system.time({
roll_mean(x, 1000)
})
setThreadOptions(numThreads = 8L)
t2 <- system.time({
roll_mean(x, 1000)
})
t1; t2
# user system elapsed
# 0.286 0.037 0.328
# user system elapsed
# 0.283 0.001 0.282
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment