This is the code I use to benchmark R
. Last changed March 31, 2016.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
set.seed(4987) library(microbenchmark) library(Matrix) A <- matrix(rnorm(1e6, 1e3, 1e2), ncol = 1e3) B <- matrix(rnorm(1e6, 1e3, 1e2), ncol = 1e3) A <- crossprod(A, A) A <- A * 1000 / mean(A) colnames(A) <- colnames(B) <- NULL options(scipen=4, digits = 3) BLAS <- microbenchmark( sort(c(as.vector(A), as.vector(B))), det(A), A %*% B, t(A) %*% B, crossprod(A, B), solve(A), solve(A, t(B)), solve(B), chol(A), chol(B, pivot = TRUE), qr(A, LAPACK = TRUE), svd(A), eigen(A, symmetric = TRUE), eigen(A, symmetric = FALSE), eigen(B, symmetric = FALSE), lu(A), fft(A), Hilbert(3000), toeplitz(A[1:500, 1]), princomp(A), times=25L, unit='ms', control = list(order = 'block') ) NotBLAS <- microbenchmark( A + 2, A - 2, A * 2, A / 2, A * 0.5, A ^ 2, sqrt(A[1:10000]), sin(A[1:10000]), A + B, A - B, A * B, A / B, A[1:1e5] %% B[1:1e5], A[1:1e5] %/% B[1:1e5], times = 5000L, unit='ms', control = list(order = 'block') ) |