Skip to content

Instantly share code, notes, and snippets.

@sileht
Last active August 29, 2017 18:30
Show Gist options
  • Save sileht/5ce2163fa23b4376f094edb4dee47332 to your computer and use it in GitHub Desktop.
Save sileht/5ce2163fa23b4376f094edb4dee47332 to your computer and use it in GitHub Desktop.
test-pytimeparse
import timeit
print("https://github.com/wroberts/pytimeparse/pull/14")
values = ["-%s seconds" % i for i in xrange(10)]
valuesbig = ["-%s seconds" % i for i in xrange(100)]
valuesbigger = ["-%s seconds" % i for i in xrange(1000)]
for v in ["values", "valuesbig", "valuesbigger"]:
print(timeit.timeit(
"[timeparse(v) for v in %s]" % v,
"from pytimeparse.timeparse import timeparse; from __main__ import values, valuesbig, valuesbigger",
number=1000
))
print("")
print("pandas")
for v in ["values", "valuesbig", "valuesbigger"]:
print(timeit.timeit(
"[pd.to_timedelta(v, box=False) for v in %s]" % v,
"import pandas as pd; from __main__ import values, valuesbig, valuesbigger",
number=1000
))
@chungg
Copy link

chungg commented Aug 29, 2017

except pd.to_timedelta accepts a list so you don't need to to list comprehension :)

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