Skip to content

Instantly share code, notes, and snippets.

@mauro3
mauro3 / v0.2.1
Last active August 29, 2015 14:02
sparse_getindex_small1,Small sparse matrix with 10 entries/column, indexing with integers,0.448931,0.468407,0.454377,0.007985
sparse_getindex_small2,Small sparse matrix with 100 entries/column, indexing with integers,0.651765,0.696139,0.668417,0.016734
sparse_getindex_medium1,Medium sparse matrix with 10 entries/column, indexing with integers,0.795296,0.856736,0.811085,0.025680
sparse_getindex_medium2,Medium sparse matrix with 100 entries/column, indexing with integers,1.253497,1.260646,1.256850,0.003009
sparse_getindex_small3,Sparse matrix with 10 entries/column, indexing rows with a range,1.731063,9.425001,4.829933,3.849493
sparse_getindex_small4,Sparse matrix with 10 entries/column, indexing rows with a ordered array,1.619907,8.389759,2.987851,3.019779
sparse_getindex_small5,Sparse matrix with 10 entries/column, indexing rows with a disordered array,1.837361,1.860880,1.850504,0.009153
sparse_getindex_small6,Sparse matrix with 10 entries/column, indexing rows with a range,0.616219,0.638256,0.621277,0.009504
using Base.Order
using Base.SparseMatrix.binarysearch
const N = 10^2
const NN = N*10^2
const rowvalA = sort(randperm(NN)[1:N])
const iss = randperm(NN) # disordered needle
const iso = [1:NN] # ordered needles
function h1(rowvalA, iss)
@mauro3
mauro3 / julia_0.2.1
Last active August 29, 2015 14:02
sparse perf.jl
julia,sparse_getindex_small1,0.451012,0.483519,0.461447,0.012916
julia,sparse_getindex_small2,0.686494,0.718988,0.700459,0.016626
julia,sparse_getindex_medium1,0.783230,0.841894,0.803835,0.022526
julia,sparse_getindex_medium2,1.246590,1.276114,1.262807,0.011405
julia,sparse_getindex_small3,1.742440,9.295122,4.759420,3.807503
julia,sparse_getindex_small4,1.607372,8.230405,2.954001,2.949752
julia,sparse_getindex_small5,1.829975,1.870861,1.846175,0.018316
julia,sparse_getindex_small6,0.632674,0.673803,0.642136,0.017769
julia,sparse_getindex_small7,0.594250,0.604567,0.597951,0.004128
julia,sparse_getindex_small8,0.596583,0.607086,0.598952,0.004554
# Binary and linear search are about equally fast for a haystack of
# size ~38 (Array{I<:Integer}). For Array{Float64} it's about size ~15.
# For arrays of pointers binsearch probably is always faster.
#
# For Array(Int}
# For n=1 to 9, linear search takes about 50% of binary search
#
# For n=10 to 20, linear search takes about 75% of binary search
#
# Now, this chap finds that in C linear search is faster up to array size ~ 64
@mauro3
mauro3 / new_timings
Created June 5, 2014 10:54
Sparse getindex performance
NEW
m = vs[3]; =====================================
Integer indexing: elapsed time: 0.004826669 seconds (96088 bytes allocated)
#### indexing with ranges
Whole column-wise indexing: elapsed time: 0.001638723 seconds (6527288 bytes allocated)
Column-wise indexing with a range of rows: elapsed time: 0.003093329 seconds (123832 bytes allocated)
Whole row-wise indexing: elapsed time: 6.059387827 seconds (32650872 bytes allocated)