Created
October 27, 2017 11:41
-
-
Save csgillespie/441e087da6498a0ac81a465995d298a1 to your computer and use it in GitHub Desktop.
Slow down
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##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