Commit f8c2fb09 authored by Radford Neal's avatar Radford Neal

add assignperf tests

parent 15662f3e
Modifications to do_set and applydefine for complex assignments.
Modifications to do_set for complex assignments, replacing the
old applydefine function (which is kept around for comparison).
Also, added a codePromises option for deparse, and NA option for
evaluate in dump, which goes with these being needed for better
......@@ -18,3 +19,7 @@ traceback output for errors like the following:
Updated the saved output of reg-tests-2.Rout and reg-tests-1b.Rout
to show new error messages.
Created a new test set, assignperf.R, which tests whether complex
assignments avoid duplication when they should (and incidently does
some correctness tests).
......@@ -26,7 +26,8 @@ test-src-sloppy-1 = \
print-tests.R \
lapack.R \
datasets.R \
iec60559.R
iec60559.R \
assignperf.R
test-src-sloppy-auto =
test-src-1 = $(test-src-strict-1) $(test-src-sloppy-1)
......
# Test performance of complex assignments, by seeing what storage
# allocation is done.
print(1) # get some stuff allocated before Rprofmemt activatived.
vsize <- 100 # must be multiple of 4
Rprofmemt(nelem=vsize)
# One-level assignments.
a <- numeric(vsize)
a[10] <- 3 # shouldn't duplicate
a[[11]] <- 4 # shouldn't duplicate
print(a)
a <- c(list(a=4,b=FALSE),rep(list(7),vsize-2))
a$b <- TRUE # shouldn't duplicate
a[10] <- 3 # shouldn't duplicate
a[[11]] <- 4 # shouldn't duplicate
print(unlist(a))
names(a) <- NULL # shouldn't duplicate
print(unlist(a))
a <- numeric(vsize)
b <- a
a[[3]] <- -1 # will have to duplicate
b[[4]] <- -2 # shouldn't duplicate
print(a)
print(b)
a <- numeric(vsize)
n <- paste0("xx",1:vsize)
names(a) <- n # shouldn't duplicate numeric part, might duplicate names
# Two-level assignments.
a <- rep(list(a=1,b=1:vsize,c="xx",d="yy"),vsize/4)
a$b[3] <- 99L # will need to duplicate, because of repeated elements
print(a$b+1000L) # don't pass a$b itself, since affects NAMEDCNT
a$b[3] <- 99L # shouldn't duplicate now
print(a$b+1000L)
print(a[[6]]) # should still be 1:vsize
a$b[3] <- 99.1 # will have to coerce to real, shouldn't duplicate int vec
print(a$b+1000)
a$b[3] <- 99.1 # shouldn't duplicate now
print(a$b+1000)
a[[10]][2] <- 40L # will need to duplicate, because of repeated elements
print(a[[10]]+1000L)
a[[10]][2] <- 40L # shouldn't duplicate now
print(a[[10]]+1000L)
a <- c(list(x=c(0,y=1,rep(0,vsize-2))),rep(list("a"),vsize-1))
a$x[2] <- 12 # shouldn't duplicate
print(a$x+1000)
a$x[[2]] <- 13 # shouldn't duplicate
print(a$x+1000)
a$x["y"] <- 14 # shouldn't duplicate
print(a$x+1000)
a$x[["y"]] <- 15 # shouldn't duplicate
print(a$x+1000)
a <- numeric(vsize)
n <- paste0("xx",1:vsize)
names(a) <- n # shouldn't duplicate numeric part
names(a)[2] <- "q"# shouldn't duplicate anything
print(a)
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment