Created
June 6, 2019 14:26
-
-
Save hhatto/8f90945916fe76a0c3cf7a2c7d7d332e to your computer and use it in GitHub Desktop.
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 benchmarker import Benchmarker | |
with Benchmarker(1000*500, width=40) as bench: | |
@bench("datetime->str(strftime)") | |
def _(bm): | |
d = datetime(2019, 1, 2) | |
for i in bm: | |
_ = d.strftime("%Y-%m-%d") | |
@bench("datetime->str(direct)") | |
def _(bm): | |
d = datetime(2019, 1, 2) | |
for i in bm: | |
_ = "{}-{:02d}-{:02d}".format(d.year, d.month, d.day) | |
@bench("str->datetime(strptime)") | |
def _(bm): | |
d = "2019-01-02" | |
for i in bm: | |
_ = datetime.strptime(d, "%Y-%m-%d") | |
@bench("str->datetime(direct)") | |
def _(bm): | |
d = "2019-01-02" | |
for i in bm: | |
year, month, day = d.split("-") | |
_ = datetime(int(year), int(month), int(day)) |
Author
hhatto
commented
Jun 6, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment