Skip to content

Instantly share code, notes, and snippets.

@csgillespie
Created October 27, 2017 11:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save csgillespie/441e087da6498a0ac81a465995d298a1 to your computer and use it in GitHub Desktop.
Save csgillespie/441e087da6498a0ac81a465995d298a1 to your computer and use it in GitHub Desktop.
Slow down
##R version 3.4.2 (2017-09-28)
##Platform: x86_64-pc-linux-gnu (64-bit)
##Running under: Ubuntu 16.04.3 LTS
bm_prog_toeplitz = function() {
N = 3000
ans = rep(0, N*N)
dim(ans) = c(N, N)
system.time({
for (j in 1:N) {
for (k in 1:N) {
ans[k,j] = abs(j - k) + 1
}
}
}
)
}
## Takes around 7 seconds
bm_prog_toeplitz()
## Around 2 seconds
N = 3000
ans = rep(0, N*N)
dim(ans) = c(N, N)
system.time({
for (j in 1:N) {
for (k in 1:N) {
ans[k,j] = abs(j - k) + 1
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment