forked from rdpeng/ProgrammingAssignment2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestCacheMatrix.R
More file actions
27 lines (18 loc) · 821 Bytes
/
testCacheMatrix.R
File metadata and controls
27 lines (18 loc) · 821 Bytes
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
source("cachematrix.R")
timed.solver <- function(msg, cache.matrix) {
message(msg)
print(system.time(cacheSolve(cache.matrix)))
}
set.seed(1234)
dimension <- 1000
input.matrix <- matrix(rnorm(1:dimension^2), dimension, dimension)
cache.matrix <- makeCacheMatrix(input.matrix)
timed.solver("First test, should not use cached version", cache.matrix)
timed.solver("Second test, should use cached version", cache.matrix)
cache.matrix$set(matrix(4:1,2,2))
timed.solver("Third test, changing the matrix should invalidate the cached version",
cache.matrix)
timed.solver("Fourth test, now the inverse should be cached again",cache.matrix)
cache.matrix$set(matrix(4:1,2,2))
timed.solver("Fifth test, setting the matrix with an identical matrix should not invalidate the cache",
cache.matrix)