[Rcpp-commits] r3679 - in pkg/RcppCNPy: . demo
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sat Jul 7 18:57:51 CEST 2012
Author: edd
Date: 2012-07-07 18:57:50 +0200 (Sat, 07 Jul 2012)
New Revision: 3679
Added:
pkg/RcppCNPy/demo/
pkg/RcppCNPy/demo/timings.R
Log:
o added a simple demo with a timing benchmark
Added: pkg/RcppCNPy/demo/timings.R
===================================================================
--- pkg/RcppCNPy/demo/timings.R (rev 0)
+++ pkg/RcppCNPy/demo/timings.R 2012-07-07 16:57:50 UTC (rev 3679)
@@ -0,0 +1,39 @@
+
+library(RcppCNPy)
+library(rbenchmark)
+
+## expensive: N <- 1e5
+## cheaper:
+n <- 1e4
+k <- 50
+
+M <- matrix(seq(1.0, n*k, by=1.0), n, k)
+
+txtfile <- tempfile(fileext=".txt")
+write.table(M, file=txtfile)
+
+pyfile <- tempfile(fileext=".py")
+npySave(pyfile, M)
+
+pygzfile <- tempfile(fileext=".py")
+npySave(pygzfile, M)
+system(paste("gzip -9", pygzfile))
+pygzfile <- paste(pygzfile, ".gz", sep="")
+
+print(do.call(rbind, (lapply(c(txtfile, pyfile, pygzfile),
+ function(f) file.info(f)["size"]))))
+
+res <- benchmark(read.table(txtfile),
+ npyLoad(pyfile),
+ npyLoad(pygzfile),
+ order="relative",
+ columns=c("test", "replications", "elapsed", "relative"),
+ replications=10)
+print(res)
+
+unlink(txtfile)
+unlink(pyfile)
+unlink(pygzfile)
+
+
+
More information about the Rcpp-commits
mailing list