inst/book/C-PortfolioOptimization/R/sumSquares.R

trials <- 1000L; n <- 20000L; ee <- rnorm(n)
system.time(for (i in 1L:trials) z1 <- sum(ee^2))
system.time(for (i in 1L:trials) z2 <- ee %*% ee)
system.time(for (i in 1L:trials) z3 <- crossprod(ee))
stopifnot(all.equal(as.numeric(z1), as.numeric(z2)))
stopifnot(all.equal(as.numeric(z2), as.numeric(z3)))

Try the NMOF package in your browser

Any scripts or data that you put into this service are public.

NMOF documentation built on May 2, 2019, 6:39 p.m.