33 lines
650 B
R
33 lines
650 B
R
source("mat.R")
|
|
|
|
time <- function(f) {
|
|
start_time <- Sys.time()
|
|
val <- f()
|
|
end_time <- Sys.time()
|
|
print(end_time - start_time)
|
|
return(val)
|
|
}
|
|
|
|
sizes <- c(5, 10, 50, 100, 500, 1000, 5000, 10000, 20000, 30000)
|
|
# sizes <- c(5, 10, 50, 100, 500, 1000, 5000, 10000)
|
|
|
|
# warm up
|
|
|
|
for (size in 30:50) {
|
|
m <- matrix(runif(size * size), nrow = size, ncol = size)
|
|
sum1(m)
|
|
sum2(m)
|
|
}
|
|
|
|
for (size in sizes) {
|
|
m <- matrix(runif(size * size), nrow = size, ncol = size)
|
|
|
|
cat(sprintf("Matrix size: %dx%d\n", size, size))
|
|
cat("sum1 run duration: ")
|
|
time(function() sum1(m))
|
|
cat("sum2 run duration: ")
|
|
time(function() sum2(m))
|
|
cat("\n")
|
|
}
|
|
|