Skip to content

Instantly share code, notes, and snippets.

@matthewrmshin
Created July 8, 2015 13:13
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 matthewrmshin/cabf70970b2dc7e85123 to your computer and use it in GitHub Desktop.
Save matthewrmshin/cabf70970b2dc7e85123 to your computer and use it in GitHub Desktop.
Proof that time.time is quicker than datetime.datetime.utcnow
#!/usr/bin/python
from datetime import datetime
from time import clock, time
N_TIMES = 100000
def main():
begin = clock()
for _ in range(N_TIMES):
time()
print ["time()", clock() - begin]
begin = clock()
for _ in range(N_TIMES):
datetime.utcnow()
print ["datetime.utcnow()", clock() - begin]
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment