Skip to content

Instantly share code, notes, and snippets.

@giupo
Created October 30, 2012 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save giupo/3981625 to your computer and use it in GitHub Desktop.
Save giupo/3981625 to your computer and use it in GitHub Desktop.
R-Python apples-to-apples tests
#
# I'm running the same tests described here : http://wesmckinney.com/blog/?p=268
#
from pandas import *
from pandas.util.testing import rands
n = 100000
indices = Index([rands(10) for _ in xrange(n)])
def sample(values, k):
from random import shuffle
sampler = np.arange(len(values))
shuffle(sampler)
return values.take(sampler[:k])
subsample_size = 90000
x = Series(np.random.randn(n), indices)
y = Series(np.random.randn(subsample_size),
index=sample(indices, subsample_size))
xs = x.sort_index()
ys = y.sort_index()
from pandas.util.testing import rands
# -----------
>>> timeit x+y
1 loops, best of 3: 349 ms per loop
>>> timeit xs+ys
1 loops, best of 3: 85.7 ms per loop
library(zoo)
indices = rep(NA, 100000)
for (i in 1:100000)
indices[i] <- paste(sample(letters, 10), collapse="")
timings <- numeric()
x <- zoo(rnorm(100000), indices)
y <- zoo(rnorm(90000), indices[sample(1:100000, 90000)])
for (i in 1:10) {
gc()
timings[i] = system.time(x + y)[3]
}
> mean(timings)
[1] 3.2465
@coolscr
Copy link

coolscr commented Nov 17, 2021

fun and cool

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment