Skip to content

Performance vs. built-in time.strptime #5

@derekenos

Description

@derekenos

Outputs

This Library

python3.9 -c "from __init__ import strptime; print(strptime('2020-12-28T12:00:00Z', '%Y-%m-%dT%H:%M:%SZ'))"

Outputs

struct_time(tm_year=2020, tm_mon=12, tm_mday=28, tm_hour=12, tm_min=0, tm_sec=0, tm_wday=0, tm_yday=363)

Built-in

python3.9 -c "from time import strptime; print(strptime('2020-12-28T12:00:00Z', '%Y-%m-%dT%H:%M:%SZ'))"

Outputs

time.struct_time(tm_year=2020, tm_mon=12, tm_mday=28, tm_hour=12, tm_min=0, tm_sec=0, tm_wday=0, tm_yday=363, tm_isdst=-1)

1000 executions

Python 2.7

This Library

$ time for i in {0..1000}; do python -c "from __init__ import strptime; strptime('2020-12-28T12:00:00Z', '%Y-%m-%dT%H:%M:%SZ')"; done

real	0m10.061s
user	0m7.183s
sys	0m2.957s

Built-in

$ time for i in {0..1000}; do python -c "from time import strptime; strptime('2020-12-28T12:00:00Z', '%Y-%m-%dT%H:%M:%SZ')"; done

real	0m11.979s
user	0m9.452s
sys	0m2.610s

Python 3.9

This Library

$ time for i in {0..1000}; do python3.9 -c "from __init__ import strptime; strptime('2020-12-28T12:00:00Z', '%Y-%m-%dT%H:%M:%SZ')"; done

real	0m15.709s
user	0m12.771s
sys	0m3.033s

Built-in

$ time for i in {0..1000}; do python3.9 -c "from time import strptime; strptime('2020-12-28T12:00:00Z', '%Y-%m-%dT%H:%M:%SZ')"; done

real	0m24.300s
user	0m20.659s
sys	0m3.734s

10,000 executions

Python 2.7

This Library

$ time for i in {0..10000}; do python -c "from time import strptime; strptime('2020-12-28T12:00:00Z', '%Y-%m-%dT%H:%M:%SZ')"; done

real	1m58.888s
user	1m29.695s
sys	0m30.012s

Built-in

$ time for i in {0..10000}; do python -c "from __init__ import strptime; strptime('2020-12-28T12:00:00Z', '%Y-%m-%dT%H:%M:%SZ')"; done

real	1m44.281s
user	1m15.622s
sys	0m29.298s

Python 3.9

This Library

$ time for i in {0..10000}; do python3.9 -c "from __init__ import strptime; strptime('2020-12-28T12:00:00Z', '%Y-%m-%dT%H:%M:%SZ')"; done

real	2m36.523s
user	2m7.484s
sys	0m30.014s

Built-in

$ time for i in {0..10000}; do python3.9 -c "from time import strptime; strptime('2020-12-28T12:00:00Z', '%Y-%m-%dT%H:%M:%SZ')"; done

real	4m0.683s
user	3m25.811s
sys	0m35.859s

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions