Created
August 30, 2017 16:24
-
-
Save ajtritt/ab42e5f6b0f4fdcdde20b84f6aef011d to your computer and use it in GitHub Desktop.
Benchamark ISO time arithmetic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime | |
from timeit import timeit | |
iso_setup = ''' | |
from datetime import datetime | |
iso_start = "2017-08-30T16:01:18Z" | |
iso_end = "2017-08-30T16:01:20Z" | |
fmt = "%Y-%m-%dT%H:%M:%SZ" | |
''' | |
iso_run = ''' | |
s = datetime.strptime(iso_start, fmt) | |
e = datetime.strptime(iso_end, fmt) | |
seconds = (e-s).seconds | |
''' | |
unix_setup = ''' | |
unix_start = 1504108878 | |
unix_end = 1504108880 | |
''' | |
unix_run = ''' | |
seconds = unix_end - unix_start | |
''' | |
it = 100000 | |
print('timing ISO time arithmetic') | |
iso_result = timeit(setup=iso_setup, stmt=iso_run, number=it) | |
print('timing unix time arithmetic') | |
unix_result = timeit(setup=unix_setup, stmt=unix_run, number=it) | |
print('iso: %s' % iso_result) | |
print('unix: %s' % unix_result) | |
print('factor: %s' % (iso_result/unix_result)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment