evoalgs-r-practise/w1/mat_tests.R

33 lines
650 B
R
Raw Permalink Normal View History

2024-05-06 06:54:48 +00:00
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")
}