powered by
Calculate sum(x^2), but faster when the number of elements exceeds 1000.
sum(x^2)
A numerical scalar
double, integer, or logical vector/matrix
x <- rnorm(10000) sumsquared(x) # Compare speed microbenchmark::microbenchmark( cpp = {sumsquared(x)}, r = {sum(x^2)} )
Run the code above in your browser using DataLab