Skip to content

Instantly share code, notes, and snippets.

@chriswl
Last active December 11, 2015 10:09
Show Gist options
  • Save chriswl/4584895 to your computer and use it in GitHub Desktop.
Save chriswl/4584895 to your computer and use it in GitHub Desktop.
timing itemgetter vs. indexing
import timeit
timeit.timeit(stmt= "[a[i] for i in b]", setup = "from operator import itemgetter; import numpy as np; a = list(np.random.random(100)); b = np.random.random_integers(100, size=1000) - 1", number=1000)
timeit.timeit(stmt= "itemgetter(*b)(a)", setup = "from operator import itemgetter; import numpy as np; a = list(np.random.random(100)); b = np.random.random_integers(100, size=1000) - 1", number=1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment