-
Notifications
You must be signed in to change notification settings - Fork 8
/
benchmark-revolution.R
75 lines (57 loc) · 2.14 KB
/
benchmark-revolution.R
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# source: https://gist.github.com/andrie/24c9672f1ea39af89c66#file-rro-mkl-benchmark-r
runs = 10
results = data.frame(name=character(), time=numeric())
cat(c("Runs :", runs, "\n"))
# Initialization
set.seed (1)
m <- 10000
n <- 5000
A <- matrix (runif (m*n),m,n)
cat("Matrix Multiply : ")
cumulate = 0
for (i in 1:runs)
cumulate = cumulate + as.numeric(system.time (B <- crossprod(A))[3])
results = rbind(results, data.frame(name="Matrix Multiply",
time=cumulate/runs))
cat(c(cumulate/runs, "\n"))
cat("Cholesky Factorization : ")
cumulate = 0
for (i in 1:runs)
cumulate = cumulate + as.numeric(system.time (C <- chol(B))[3])
results = rbind(results, data.frame(name="Cholesky Factorization",
time=cumulate/runs))
cat(c(cumulate/runs, "\n"))
cat("Singular Value Deomposition : ")
m <- 10000
n <- 2000
A <- matrix (runif (m*n),m,n)
cumulate = 0
for (i in 1:runs)
cumulate = cumulate + as.numeric(system.time (S <- svd (A,nu=0,nv=0))[3])
results = rbind(results, data.frame(name="Singular Value Deomposition",
time=cumulate/runs))
cat(c(cumulate/runs, "\n"))
cat("Principal Components Analysis : ")
m <- 10000
n <- 2000
A <- matrix (runif (m*n),m,n)
cumulate = 0
for (i in 1:runs)
cumulate = cumulate + as.numeric(system.time (P <- prcomp(A))[3])
results = rbind(results, data.frame(name="Principal Components Analysis",
time=cumulate/runs))
cat(c(cumulate/runs, "\n"))
cat("Linear Discriminant Analysis : ")
library('MASS')
g <- 5
k <- round (m/2)
A <- data.frame (A, fac=sample (LETTERS[1:g],m,replace=TRUE))
train <- sample(1:m, k)
cumulate = 0
for (i in 1:runs)
cumulate = cumulate + as.numeric(system.time (L <- lda(fac ~., data=A, prior=rep(1,g)/g, subset=train))[3])
results = rbind(results, data.frame(name="Linear Discriminant Analysis",
time=cumulate/runs))
cat(c(cumulate/runs, "\n"))
attr(results, "runs") = runs
saveRDS(results, paste0("test-revolution-", ifelse(exists("blasLibName"), blasLibName, ""), ".rds"))