Is the right way to rectify the global scope problem by wrapping the benchmark code in a function and running that?
If so, I'm still able to replicate this performance comparison with similar results. Matlab's about 2x slower than Scipy which surprised me a little, but Scipy probably has a specialized operator for sparse A_mul_Bt whereas Matlab's parser might not be that smart. Doesn't look like anyone has written sparse matmul with transposes in linalg/sparse.jl yet, but I would find that useful enough that I'll write a few of them myself at some point if nobody else does. About 65% of the time in your test appears to be spent in the double-transpose at the end of sparse matmul (lines 175 and 176 of linalg/sparse.jl). -Tony On Friday, February 21, 2014 6:48:44 PM UTC-8, John Myles White wrote: > > Are you timing these in the global scope? That will cause a substantial > performance loss. > > — John > > On Feb 21, 2014, at 6:18 PM, Michael Schnall-Levin > <[email protected]<javascript:>> > wrote: > > > I've been doing some benchmarking of Julia vs Scipy for sparse matrix > multiplication and I'm finding that julia is significantly (~4X - 5X) > faster in some instances. > > > > I'm wondering if I'm doing something wrong, or if this is really true. > Below are some code snippets for Julia and python. Any help would be very > appreciated! > > > > ----- Julia: > > Elapsed Time on my laptop: 24.9 seconds ----- > > x_inds = Int[] > > y_inds = Int[] > > vals = Int[] > > > > for n = 1:10000 > > inds = rand(1:2000,10,1) > > for ind in inds > > push!(x_inds, ind) > > push!(y_inds, n) > > push!(vals,1) > > end > > end > > > > x = sparse(x_inds, y_inds, vals, 2000, 10000) > > > > t = time() > > for j = 1:250 > > y = x*transpose(x) > > end > > print(string(time() - t, "\n")) > > ----- > > > > ---- Python Elapsed Time on my laptop: 5.8 seconds ----- > > import numpy > > import scipy.sparse > > import time > > > > x_inds = [] > > y_inds = [] > > vals = [] > > for n in xrange(10000): > > inds = numpy.random.randint(0, 2000,10) > > > > for ind in inds: > > x_inds.append(ind) > > y_inds.append(n) > > vals.append(1) > > > > x_inds = numpy.array(x_inds) > > y_inds = numpy.array(y_inds) > > vals = numpy.array(vals) > > > > x = scipy.sparse.csc_matrix((vals, (x_inds, y_inds)), shape=(2000, > 10000)) > > > > t = time.time() > > for j in xrange(250): > > y = x*x.transpose() > > print time.time() - t > > > >
