| 1 |
library("profmem") |
| 2 |
|
| 3 |
status <- profmem_status() |
| 4 |
message("status: ", status) |
| 5 |
|
| 6 |
depth <- profmem_depth() |
| 7 |
message("depth: ", depth) |
| 8 |
|
| 9 |
if (capabilities("profmem")) { |
| 10 |
|
| 11 |
p <- profmem({ |
| 12 |
x <- raw(1000) |
| 13 |
A <- matrix(rnorm(100), ncol=10) |
| 14 |
status_2 <- profmem_status() |
| 15 |
depth_2 <- profmem_depth() |
| 16 |
message("depth_2: ", depth_2) |
| 17 |
stopifnot(depth2 == depth_+ 1) |
| 18 |
}) |
| 19 |
print(p) |
| 20 |
|
| 21 |
data <- as.data.frame(p, stringsAsFactors = FALSE) |
| 22 |
print(data) |
| 23 |
|
| 24 |
t <- total(p) |
| 25 |
print(t) |
| 26 |
stopifnot(t == sum(data$bytes, na.rm=TRUE)) |
| 27 |
|
| 28 |
|
| 29 |
foo <- function(n) { |
| 30 |
matrix(rnorm(n^2), ncol=n) |
| 31 |
} |
| 32 |
|
| 33 |
p <- profmem({ |
| 34 |
A <- matrix(rnorm(100^2), ncol=100) |
| 35 |
B <- foo(100) |
| 36 |
}) |
| 37 |
print(p) |
| 38 |
|
| 39 |
p2 <- subset(p, bytes >= 40000) |
| 40 |
print(p2) |
| 41 |
|
| 42 |
p <- profmem({ |
| 43 |
A <- matrix(rnorm(100^2), ncol=100) |
| 44 |
B <- foo(100) |
| 45 |
}, threshold = 40000) |
| 46 |
d <- as.data.frame(p, stringsAsFactors = FALSE) |
| 47 |
print(d) |
| 48 |
|
| 49 |
p1 <- subset(p, !is.na(bytes)) |
| 50 |
d1 <- as.data.frame(p1, stringsAsFactors = FALSE) |
| 51 |
|
| 52 |
p2 <- subset(p, bytes >= 40000) |
| 53 |
d2 <- as.data.frame(p2, stringsAsFactors = FALSE) |
| 54 |
print(d2) |
| 55 |
stopifnot(identical(d2, d1)) |
| 56 |
|
| 57 |
print(dim(p)) |
| 58 |
stopifnot(identical(dim(p), dim(d))) |
| 59 |
|
| 60 |
} ## if (capabilities("profmem")) |
| 61 |
|