Skip to content

Instantly share code, notes, and snippets.

@ndamclean
Created January 13, 2021 20:16
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 ndamclean/2c1113ea40199be7edd43a506748ffd7 to your computer and use it in GitHub Desktop.
Save ndamclean/2c1113ea40199be7edd43a506748ffd7 to your computer and use it in GitHub Desktop.
import ciso8601
import iso8601
import pytest
from datetime import datetime
from dateutil import parser
TIME_STR = '2019-08-28T14:34:25.518993+00:00'
TIME_STR_Z = '2019-08-28T14:34:25.518993Z'
@pytest.mark.parametrize('iso_timestamp', [TIME_STR, TIME_STR_Z])
def test_dateutil_isoparse(benchmark, iso_timestamp):
benchmark(parser.isoparse, iso_timestamp)
@pytest.mark.parametrize('iso_timestamp', [TIME_STR, TIME_STR_Z])
def test_ciso8601_parse_datetime(benchmark, iso_timestamp):
benchmark(ciso8601.parse_datetime, iso_timestamp)
@pytest.mark.parametrize('iso_timestamp', [TIME_STR, TIME_STR_Z])
def test_iso8601_parse_date(benchmark, iso_timestamp):
benchmark(iso8601.parse_date, iso_timestamp)
@pytest.mark.parametrize('iso_timestamp', [TIME_STR])
def test_datetime_fromisoformat(benchmark, iso_timestamp):
benchmark(datetime.fromisoformat, iso_timestamp)
@pytest.mark.parametrize('iso_timestamp', [TIME_STR_Z])
def test_datetime_fromisoformat_replace_z(benchmark, iso_timestamp):
def native_iso_parse(x):
return datetime.fromisoformat(x.replace('Z', '+00:00'))
benchmark(native_iso_parse, iso_timestamp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment