JuliaLang/julia — pull request #2311 by tshort (2013-02-15 15:26:18+00:00)
Title: Faster cov and cor

The existing versions of `cov` and `cor` are quite slow for matrix operations. Here is an example:

```julia
# 1000x1000 matrix
julia> n = 1000; x = reshape([1:n^2].^2., (n, n));

julia> @time res = cor(x);
elapsed time: 20.822247982025146 seconds

julia> @time res = cor(x,x');
elapsed time: 63.54162096977234 seconds

# Here's the same in R:
> N=1000;x = matrix((1:(N*N))^2,N,N)

> system.time(y2 <- cor(x))
user system elapsed
1.104 0.000 1.103

> system.time(y2 <- cor(x,t(x)))
user system elapsed
2.356 0.024 2.381
```

Here are updated timings with the new cor and cov code in this pull request.

```julia
julia> @time res = cor(x);
elapsed time: 0.12439203262329102 seconds

julia> @time res = cor(x,x');
elapsed time: 0.49039483070373535 seconds
```