In [1]:
%load_ext autoreload
%load_ext line_profiler
%autoreload 2
import cyResampling as cyR
import pyResampling as pyR
import weaveResampling as weR

N = 100000
w = random.uniform(size=N)
#w = ones(N)
w /= sum(w)

In [2]:
# Multinomial test
print 'Multinomial:'
print 'Weave'
%timeit weR.resampleMultinomial(w)
print 'Python'
%timeit pyR.resampling(w, 'mult')
print 'Cython'
%timeit cyR.resampling(w, 'multinomial')

print '\n'

# Residual test
print 'Residual:'
print 'Python'
%timeit pyR.resampling(w, 'res')
print 'Cython'
%timeit cyR.resampling(w, 'residual')

print '\n'

# Stratified test
print 'Stratified:'
print 'Weave'
%timeit weR.resampleStratified(w)
print 'Python'
%timeit pyR.resampling(w, 'strat')
print 'Cython'
%timeit cyR.resampling(w, 'stratified')

print '\n'

# Systematic test
print 'Systematic:'
print 'Weave'
%timeit weR.resampleSystematic(w)
print 'Python'
%timeit pyR.resampling(w, 'sys')
print 'Cython'
%timeit cyR.resampling(w, 'systematic')


Multinomial:
Weave
1 loops, best of 3: 3.48 s per loop
Python
1 loops, best of 3: 2.2 s per loop
Cython
1 loops, best of 3: 2.33 s per loop


Residual:
Python
1 loops, best of 3: 238 ms per loop
Cython
10 loops, best of 3: 37.3 ms per loop


Stratified:
Weave
100 loops, best of 3: 3.22 ms per loop
Python
1 loops, best of 3: 2.2 s per loop
Cython
100 loops, best of 3: 3.46 ms per loop


Systematic:
Weave
1000 loops, best of 3: 1.92 ms per loop
Python
10 loops, best of 3: 44.5 ms per loop
Cython
100 loops, best of 3: 2.31 ms per loop

In [19]:
K = 20000
avg_temp = zeros((K,N))
for k in range(K):
    avg_temp[k,:] = np.bincount(cyR.resampling(w, 'multinomial'), minlength=N)
avg = np.sum(avg_temp, axis=0)/N/K

In [20]:
print sum(abs(avg-w))


0.0056347

In [9]:
%prun cyR.resampling(w, 'systematic')




In [5]:
%lprun -f weR.resampleStratified weR.resampleStratified(w)

In [31]:
2/10000.


Out[31]:
0.0002

In [34]:
np.sum(avg,axis=0)/N/K


Out[34]:
array([  2.76000000e-05,   4.96000000e-05,   1.67400000e-04, ...,
         1.46500000e-04,   6.94000000e-05,   1.26400000e-04])

In [ ]: