-
Notifications
You must be signed in to change notification settings - Fork 8
/
benchmark-gcbd.R
81 lines (58 loc) · 2.11 KB
/
benchmark-gcbd.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
76
77
78
79
80
81
# source: CRAN gcbd package
size = c(100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1250, 1500, 1750, 2000, 2500, 3000, 3500, 4000, 4500, 5000)
runs = c( 50, 50, 50, 50, 50, 50, 50, 50, 50, 30, 30, 30, 30, 20, 20, 5, 5, 5, 5, 5)
meanTrim = 0.1
results = data.frame(t1=numeric(), t2=numeric(), t3=numeric(), t4=numeric())
library(Matrix)
# functions
getMatrix <- function(N) {
a <- rnorm(N*N)
dim(a) <- c(N,N)
invisible(gc())
invisible(a)
}
matmultBenchmark <- function(N, n, trim=0.1) {
a <- getMatrix(N)
traw <- replicate(n, system.time(crossprod(a))[3])
tmean <- mean(traw,trim=trim)
}
qrBenchmark <- function(N, n, trim=0.1) {
a <- getMatrix(N)
traw <- replicate(n, system.time(qr(a, LAPACK=TRUE))[3])
tmean <- mean(traw,trim=trim)
}
svdBenchmark <- function(N, n, trim=0.1) {
a <- getMatrix(N)
traw <- replicate(n, system.time(svd(a))[3])
tmean <- mean(traw,trim=trim)
}
luBenchmark <- function(N, n, trim=0.1) {
a <- getMatrix(N)
traw <- replicate(n, system.time(lu(a))[3])
tmean <- mean(traw,trim=trim)
}
# Initialization
set.seed (1)
cat(paste0("Mean trim : ", meanTrim, "\n"))
for (i in 1:length(size))
{
n = size[i]
r = runs[i]
cat(paste0("Size : ", n, "\n"))
cat(paste0("Runs : ", r, "\n"))
t1 = matmultBenchmark(n, r, meanTrim)
cat(paste0("Matrix Multiply : ", t1, "\n"))
t2 = qrBenchmark(n, r, meanTrim)
cat(paste0("QR Decomposition : ", t2, "\n"))
t3 = svdBenchmark(n, r, meanTrim)
cat(paste0("Singular Value Deomposition : ", t3, "\n"))
t4 = luBenchmark(n, r, meanTrim)
cat(paste0("Triangular Decomposition : ", t4, "\n"))
results = rbind(results, data.frame(t1=t1, t2=t2, t3=t3, t4=t4))
}
colnames(results) = c("Matrix Multiply", "QR Decomposition",
"Singular Value Deomposition", "Triangular Decomposition")
attr(results, "size") = size
attr(results, "runs") = runs
attr(results, "meanTrim") = meanTrim
saveRDS(results, paste0("test-gcbd-", ifelse(exists("blasLibName"), blasLibName, ""), ".rds"))