Skip to content

Commit a529c71

Browse files
authored
Merge pull request #1962 from brada4/r
Modrenize R benchmarks slightly
2 parents 89b60da + 3e601bd commit a529c71

File tree

3 files changed

+17
-45
lines changed

3 files changed

+17
-45
lines changed

benchmark/scripts/R/deig.R

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
argv <- commandArgs(trailingOnly = TRUE)
44

5+
if (!is.null(options("matprod")[[1]])) options(matprod = "blas")
6+
57
nfrom <- 128
68
nto <- 2048
79
nstep <- 128
@@ -19,37 +21,28 @@ if (length(argv) > 0) {
1921
loops <- as.numeric(argv[z])
2022
}
2123
}
22-
2324
}
2425

2526
p <- Sys.getenv("OPENBLAS_LOOPS")
2627
if (p != "") {
2728
loops <- as.numeric(p)
2829
}
2930

30-
31-
cat(sprintf(
32-
"From %.0f To %.0f Step=%.0f Loops=%.0f\n",
33-
nfrom,
34-
nto,
35-
nstep,
36-
loops
37-
))
31+
cat(sprintf("From %.0f To %.0f Step=%.0f Loops=%.0f\n", nfrom, nto, nstep, loops))
3832
cat(sprintf(" SIZE Flops Time\n"))
3933

4034
n <- nfrom
4135
while (n <= nto) {
42-
A <- matrix(rnorm(n * n), ncol = n, nrow = n)
36+
A <- matrix(rnorm(n * n), nrow = n)
4337
ev <- 0
4438
z <- system.time(for (l in 1:loops) {
4539
ev <- eigen(A)
4640
})
4741

48-
mflops <- (26.66 * n * n * n) * loops / (z[3] * 1.0e6)
42+
mflops <- (26.66 * n * n * n) * loops / (z[3] * 1e+06)
4943

5044
st <- sprintf("%.0fx%.0f :", n, n)
5145
cat(sprintf("%20s %10.2f MFlops %10.6f sec\n", st, mflops, z[3]))
5246

5347
n <- n + nstep
54-
5548
}

benchmark/scripts/R/dgemm.R

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
argv <- commandArgs(trailingOnly = TRUE)
44

5+
if (!is.null(options("matprod")[[1]])) options(matprod = "blas")
6+
57
nfrom <- 128
68
nto <- 2048
79
nstep <- 128
@@ -19,46 +21,31 @@ if (length(argv) > 0) {
1921
loops <- as.numeric(argv[z])
2022
}
2123
}
22-
2324
}
2425

2526
p <- Sys.getenv("OPENBLAS_LOOPS")
2627
if (p != "") {
2728
loops <- as.numeric(p)
2829
}
2930

30-
31-
cat(sprintf(
32-
"From %.0f To %.0f Step=%.0f Loops=%.0f\n",
33-
nfrom,
34-
nto,
35-
nstep,
36-
loops
37-
))
31+
cat(sprintf("From %.0f To %.0f Step=%.0f Loops=%.0f\n", nfrom, nto, nstep, loops))
3832
cat(sprintf(" SIZE Flops Time\n"))
3933

4034
n <- nfrom
4135
while (n <= nto) {
42-
A <- matrix(runif(n * n),
43-
ncol = n,
44-
nrow = n,
45-
byrow = TRUE)
46-
B <- matrix(runif(n * n),
47-
ncol = n,
48-
nrow = n,
49-
byrow = TRUE)
36+
A <- matrix(runif(n * n), nrow = n)
37+
B <- matrix(runif(n * n), nrow = n)
5038
C <- 1
5139

5240
z <- system.time(for (l in 1:loops) {
5341
C <- A %*% B
5442
l <- l + 1
5543
})
5644

57-
mflops <- (2.0 * n * n * n) * loops / (z[3] * 1.0e6)
45+
mflops <- (2.0 * n * n * n) * loops / (z[3] * 1e+06)
5846

5947
st <- sprintf("%.0fx%.0f :", n, n)
6048
cat(sprintf("%20s %10.2f MFlops %10.6f sec\n", st, mflops, z[3]))
6149

6250
n <- n + nstep
63-
6451
}

benchmark/scripts/R/dsolve.R

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
argv <- commandArgs(trailingOnly = TRUE)
44

5+
if (!is.null(options("matprod")[[1]])) options(matprod = "blas")
6+
57
nfrom <- 128
68
nto <- 2048
79
nstep <- 128
@@ -19,39 +21,29 @@ if (length(argv) > 0) {
1921
loops <- as.numeric(argv[z])
2022
}
2123
}
22-
2324
}
2425

2526
p <- Sys.getenv("OPENBLAS_LOOPS")
2627
if (p != "") {
2728
loops <- as.numeric(p)
2829
}
2930

30-
31-
cat(sprintf(
32-
"From %.0f To %.0f Step=%.0f Loops=%.0f\n",
33-
nfrom,
34-
nto,
35-
nstep,
36-
loops
37-
))
31+
cat(sprintf("From %.0f To %.0f Step=%.0f Loops=%.0f\n", nfrom, nto, nstep, loops))
3832
cat(sprintf(" SIZE Flops Time\n"))
3933

4034
n <- nfrom
4135
while (n <= nto) {
42-
A <- matrix(rnorm(n * n), ncol = n, nrow = n)
43-
B <- matrix(rnorm(n * n), ncol = n, nrow = n)
36+
A <- matrix(rnorm(n * n), nrow = n)
37+
B <- matrix(rnorm(n * n), nrow = n)
4438

4539
z <- system.time(for (l in 1:loops) {
4640
solve(A, B)
4741
})
4842

49-
mflops <-
50-
(2.0 / 3.0 * n * n * n + 2.0 * n * n * n) * loops / (z[3] * 1.0e6)
43+
mflops <- (8.0 / 3 * n * n * n) * loops / (z[3] * 1e+06)
5144

5245
st <- sprintf("%.0fx%.0f :", n, n)
5346
cat(sprintf("%20s %10.2f MFlops %10.6f sec\n", st, mflops, z[3]))
5447

5548
n <- n + nstep
56-
5749
}

0 commit comments

Comments
 (0)