From c35929dc24f590f0d19c21a04025ea0db9adf6a5 Mon Sep 17 00:00:00 2001 From: Michael Overmeyer Date: Mon, 16 Oct 2023 14:08:03 -0400 Subject: [PATCH 1/3] Update benchmarks for Python 3.12 --- README.rst | 166 ++++++++++++++--------------- benchmarking/format_results.py | 4 +- benchmarking/perform_comparison.py | 8 +- benchmarking/tox.ini | 6 +- 4 files changed, 95 insertions(+), 89 deletions(-) diff --git a/README.rst b/README.rst index bb71f2a..8173e67 100644 --- a/README.rst +++ b/README.rst @@ -81,45 +81,45 @@ Parsing a timestamp with no time zone information (e.g., ``2014-01-09T21:48:00`` .. table:: - +--------------------------------+-----------+-----------+----------+----------+----------+-------------------------------+--------------------------------------------------+ - | Module |Python 3.11|Python 3.10|Python 3.9|Python 3.8|Python 3.7| Python 2.7 |Relative slowdown (versus ciso8601, latest Python)| - +================================+===========+===========+==========+==========+==========+===============================+==================================================+ - |ciso8601 |84.5 nsec |111 nsec |102 nsec |111 nsec |112 nsec |134 nsec |N/A | - +--------------------------------+-----------+-----------+----------+----------+----------+-------------------------------+--------------------------------------------------+ - |backports.datetime_fromisoformat|N/A |107 nsec |105 nsec |117 nsec |112 nsec |N/A |1.0x | - +--------------------------------+-----------+-----------+----------+----------+----------+-------------------------------+--------------------------------------------------+ - |datetime (builtin) |114 nsec |N/A |N/A |N/A |N/A |N/A |1.4x | - +--------------------------------+-----------+-----------+----------+----------+----------+-------------------------------+--------------------------------------------------+ - |pendulum |174 nsec |177 nsec |164 nsec |201 nsec |202 nsec |8.52 usec |2.1x | - +--------------------------------+-----------+-----------+----------+----------+----------+-------------------------------+--------------------------------------------------+ - |udatetime |593 nsec |627 nsec |640 nsec |713 nsec |660 nsec |586 nsec |7.0x | - +--------------------------------+-----------+-----------+----------+----------+----------+-------------------------------+--------------------------------------------------+ - |str2date |5.32 usec |6.14 usec |5.88 usec |6.68 usec |6.53 usec |**Incorrect Result** (``None``)|62.9x | - +--------------------------------+-----------+-----------+----------+----------+----------+-------------------------------+--------------------------------------------------+ - |iso8601 |7.28 usec |8.32 usec |8.12 usec |9.59 usec |8.78 usec |25.7 usec |86.1x | - +--------------------------------+-----------+-----------+----------+----------+----------+-------------------------------+--------------------------------------------------+ - |iso8601utils |N/A |N/A |7.91 usec |9.28 usec |8.81 usec |11.2 usec |77.5x | - +--------------------------------+-----------+-----------+----------+----------+----------+-------------------------------+--------------------------------------------------+ - |isodate |8.21 usec |9.5 usec |9.05 usec |10.8 usec |10.5 usec |44.1 usec |97.1x | - +--------------------------------+-----------+-----------+----------+----------+----------+-------------------------------+--------------------------------------------------+ - |PySO8601 |12.9 usec |14.8 usec |15 usec |17.2 usec |16.3 usec |17.7 usec |152.9x | - +--------------------------------+-----------+-----------+----------+----------+----------+-------------------------------+--------------------------------------------------+ - |aniso8601 |16.8 usec |22.1 usec |21 usec |23.5 usec |24.7 usec |30.7 usec |198.3x | - +--------------------------------+-----------+-----------+----------+----------+----------+-------------------------------+--------------------------------------------------+ - |zulu |18 usec |21.1 usec |20.4 usec |22.1 usec |21.2 usec |N/A |212.5x | - +--------------------------------+-----------+-----------+----------+----------+----------+-------------------------------+--------------------------------------------------+ - |maya |35.1 usec |40.7 usec |40.2 usec |40.1 usec |41.8 usec |N/A |415.4x | - +--------------------------------+-----------+-----------+----------+----------+----------+-------------------------------+--------------------------------------------------+ - |python-dateutil |49 usec |59 usec |57.4 usec |63 usec |64.3 usec |119 usec |579.6x | - +--------------------------------+-----------+-----------+----------+----------+----------+-------------------------------+--------------------------------------------------+ - |arrow |51.5 usec |61.6 usec |60.3 usec |62.8 usec |65.8 usec |78.8 usec |609.7x | - +--------------------------------+-----------+-----------+----------+----------+----------+-------------------------------+--------------------------------------------------+ - |metomi-isodatetime |1.18 msec |1.67 msec |1.64 msec |1.73 msec |1.81 msec |N/A |13981.2x | - +--------------------------------+-----------+-----------+----------+----------+----------+-------------------------------+--------------------------------------------------+ - |moment |1.57 msec |1.62 msec |1.65 msec |1.7 msec |1.74 msec |N/A |18540.2x | - +--------------------------------+-----------+-----------+----------+----------+----------+-------------------------------+--------------------------------------------------+ - -ciso8601 takes 84.5 nsec, which is **1.4x faster than datetime (builtin)**, the next fastest Python 3.11 parser in this comparison. + +--------------------------------+-----------+-----------+-----------+----------+----------+----------+-------------------------------+--------------------------------------------------+ + | Module |Python 3.12|Python 3.11|Python 3.10|Python 3.9|Python 3.8|Python 3.7| Python 2.7 |Relative slowdown (versus ciso8601, latest Python)| + +================================+===========+===========+===========+==========+==========+==========+===============================+==================================================+ + |ciso8601 |94.4 nsec |89.2 nsec |125 nsec |117 nsec |129 nsec |122 nsec |134 nsec |N/A | + +--------------------------------+-----------+-----------+-----------+----------+----------+----------+-------------------------------+--------------------------------------------------+ + |backports.datetime_fromisoformat|N/A |N/A |112 nsec |105 nsec |106 nsec |112 nsec |N/A |0.9x | + +--------------------------------+-----------+-----------+-----------+----------+----------+----------+-------------------------------+--------------------------------------------------+ + |datetime (builtin) |129 nsec |136 nsec |N/A |N/A |N/A |N/A |N/A |1.4x | + +--------------------------------+-----------+-----------+-----------+----------+----------+----------+-------------------------------+--------------------------------------------------+ + |pendulum |N/A |184 nsec |191 nsec |191 nsec |192 nsec |204 nsec |8.52 usec |2.1x | + +--------------------------------+-----------+-----------+-----------+----------+----------+----------+-------------------------------+--------------------------------------------------+ + |udatetime |709 nsec |677 nsec |692 nsec |715 nsec |705 nsec |700 nsec |586 nsec |7.5x | + +--------------------------------+-----------+-----------+-----------+----------+----------+----------+-------------------------------+--------------------------------------------------+ + |str2date |6.84 usec |5.8 usec |6.86 usec |6.6 usec |6.47 usec |6.89 usec |**Incorrect Result** (``None``)|72.5x | + +--------------------------------+-----------+-----------+-----------+----------+----------+----------+-------------------------------+--------------------------------------------------+ + |iso8601utils |N/A |N/A |N/A |8.64 usec |8.69 usec |9.2 usec |11.2 usec |74.0x | + +--------------------------------+-----------+-----------+-----------+----------+----------+----------+-------------------------------+--------------------------------------------------+ + |iso8601 |9.41 usec |8.06 usec |9.2 usec |9.05 usec |9.35 usec |9.38 usec |25.7 usec |99.6x | + +--------------------------------+-----------+-----------+-----------+----------+----------+----------+-------------------------------+--------------------------------------------------+ + |isodate |10.5 usec |8.68 usec |10.2 usec |9.68 usec |10.1 usec |10.9 usec |44.1 usec |111.4x | + +--------------------------------+-----------+-----------+-----------+----------+----------+----------+-------------------------------+--------------------------------------------------+ + |PySO8601 |17.1 usec |13.4 usec |16.4 usec |16.1 usec |16.6 usec |17.1 usec |17.7 usec |181.2x | + +--------------------------------+-----------+-----------+-----------+----------+----------+----------+-------------------------------+--------------------------------------------------+ + |aniso8601 |21.7 usec |18.1 usec |24 usec |23.3 usec |23.7 usec |27.6 usec |30.7 usec |229.6x | + +--------------------------------+-----------+-----------+-----------+----------+----------+----------+-------------------------------+--------------------------------------------------+ + |zulu |23.5 usec |20.1 usec |22.4 usec |21.3 usec |21.8 usec |22.2 usec |N/A |248.7x | + +--------------------------------+-----------+-----------+-----------+----------+----------+----------+-------------------------------+--------------------------------------------------+ + |maya |N/A |37.4 usec |42.4 usec |42.1 usec |42.2 usec |43 usec |N/A |419.4x | + +--------------------------------+-----------+-----------+-----------+----------+----------+----------+-------------------------------+--------------------------------------------------+ + |python-dateutil |55.5 usec |51.6 usec |63 usec |62.9 usec |65.4 usec |67.8 usec |119 usec |588.0x | + +--------------------------------+-----------+-----------+-----------+----------+----------+----------+-------------------------------+--------------------------------------------------+ + |arrow |62.7 usec |54.4 usec |65.5 usec |64.6 usec |65 usec |71.2 usec |78.8 usec |664.2x | + +--------------------------------+-----------+-----------+-----------+----------+----------+----------+-------------------------------+--------------------------------------------------+ + |metomi-isodatetime |1.31 msec |1.3 msec |1.76 msec |1.78 msec |1.78 msec |1.91 msec |N/A |13823.8x | + +--------------------------------+-----------+-----------+-----------+----------+----------+----------+-------------------------------+--------------------------------------------------+ + |moment |1.79 msec |1.73 msec |1.77 msec |1.75 msec |1.79 msec |1.95 msec |N/A |18962.8x | + +--------------------------------+-----------+-----------+-----------+----------+----------+----------+-------------------------------+--------------------------------------------------+ + +ciso8601 takes 94.4 nsec, which is **1.4x faster than datetime (builtin)**, the next fastest Python 3.12 parser in this comparison. .. @@ -129,63 +129,63 @@ Parsing a timestamp with time zone information (e.g., ``2014-01-09T21:48:00-05:3 .. table:: - +--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+--------------------------------------------------+ - | Module | Python 3.11 | Python 3.10 | Python 3.9 | Python 3.8 | Python 3.7 | Python 2.7 |Relative slowdown (versus ciso8601, latest Python)| - +================================+===============================+===============================+===============================+===============================+===============================+===============================+==================================================+ - |ciso8601 |115 nsec |116 nsec |109 nsec |111 nsec |115 nsec |140 nsec |N/A | - +--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+--------------------------------------------------+ - |backports.datetime_fromisoformat|N/A |163 nsec |146 nsec |139 nsec |148 nsec |N/A |1.4x | - +--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+--------------------------------------------------+ - |datetime (builtin) |199 nsec |N/A |N/A |N/A |N/A |N/A |1.7x | - +--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+--------------------------------------------------+ - |pendulum |205 nsec |210 nsec |189 nsec |209 nsec |204 nsec |13.5 usec |1.8x | - +--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+--------------------------------------------------+ - |udatetime |745 nsec |719 nsec |731 nsec |726 nsec |734 nsec |768 nsec |6.5x | - +--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+--------------------------------------------------+ - |str2date |6.78 usec |7.55 usec |7.67 usec |7.69 usec |7.47 usec |**Incorrect Result** (``None``)|58.8x | - +--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+--------------------------------------------------+ - |iso8601 |11.1 usec |12.1 usec |12 usec |12.3 usec |12.2 usec |31.1 usec |96.1x | - +--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+--------------------------------------------------+ - |isodate |11.4 usec |12.4 usec |12.4 usec |13 usec |13.1 usec |46.7 usec |98.8x | - +--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+--------------------------------------------------+ - |iso8601utils |N/A |N/A |20.3 usec |37.8 usec |22.7 usec |28.3 usec |185.5x | - +--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+--------------------------------------------------+ - |PySO8601 |20.5 usec |22.9 usec |23.2 usec |23.5 usec |24.8 usec |25.3 usec |178.0x | - +--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+--------------------------------------------------+ - |zulu |25.5 usec |24.2 usec |23.4 usec |23.3 usec |24.3 usec |N/A |221.7x | - +--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+--------------------------------------------------+ - |aniso8601 |29.5 usec |28.5 usec |27.6 usec |30.1 usec |32.1 usec |39.2 usec |256.2x | - +--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+--------------------------------------------------+ - |maya |37.1 usec |40.4 usec |38.9 usec |40.3 usec |40.9 usec |N/A |322.0x | - +--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+--------------------------------------------------+ - |arrow |62.7 usec |73 usec |69.9 usec |71.7 usec |75.5 usec |100 usec |544.4x | - +--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+--------------------------------------------------+ - |python-dateutil |64.8 usec |76.6 usec |73.4 usec |77.6 usec |78.5 usec |148 usec |562.3x | - +--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+--------------------------------------------------+ - |metomi-isodatetime |1.22 msec |1.67 msec |1.6 msec |1.6 msec |1.76 msec |N/A |10604.3x | - +--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+--------------------------------------------------+ - |moment |**Incorrect Result** (``None``)|**Incorrect Result** (``None``)|**Incorrect Result** (``None``)|**Incorrect Result** (``None``)|**Incorrect Result** (``None``)|N/A |1782198.3x | - +--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+--------------------------------------------------+ - -ciso8601 takes 115 nsec, which is **1.7x faster than datetime (builtin)**, the next fastest Python 3.11 parser in this comparison. + +--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+--------------------------------------------------+ + | Module | Python 3.12 | Python 3.11 | Python 3.10 | Python 3.9 | Python 3.8 | Python 3.7 | Python 2.7 |Relative slowdown (versus ciso8601, latest Python)| + +================================+===============================+===============================+===============================+===============================+===============================+===============================+===============================+==================================================+ + |ciso8601 |106 nsec |97 nsec |129 nsec |125 nsec |118 nsec |132 nsec |140 nsec |N/A | + +--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+--------------------------------------------------+ + |backports.datetime_fromisoformat|N/A |N/A |148 nsec |142 nsec |139 nsec |148 nsec |N/A |1.1x | + +--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+--------------------------------------------------+ + |datetime (builtin) |197 nsec |203 nsec |N/A |N/A |N/A |N/A |N/A |1.9x | + +--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+--------------------------------------------------+ + |pendulum |N/A |210 nsec |214 nsec |209 nsec |216 nsec |225 nsec |13.5 usec |2.2x | + +--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+--------------------------------------------------+ + |udatetime |828 nsec |785 nsec |805 nsec |811 nsec |798 nsec |816 nsec |768 nsec |7.8x | + +--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+--------------------------------------------------+ + |str2date |7.79 usec |6.86 usec |7.71 usec |7.77 usec |7.62 usec |8 usec |**Incorrect Result** (``None``)|73.6x | + +--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+--------------------------------------------------+ + |iso8601 |12.9 usec |11.6 usec |13.1 usec |12.4 usec |12.9 usec |12.6 usec |31.1 usec |121.7x | + +--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+--------------------------------------------------+ + |isodate |13.6 usec |11.6 usec |13 usec |12.5 usec |12.9 usec |13.7 usec |46.7 usec |128.5x | + +--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+--------------------------------------------------+ + |iso8601utils |N/A |N/A |N/A |20.8 usec |22.5 usec |23.5 usec |28.3 usec |166.8x | + +--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+--------------------------------------------------+ + |PySO8601 |25.9 usec |20.5 usec |22.8 usec |24 usec |23.7 usec |24.3 usec |25.3 usec |244.4x | + +--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+--------------------------------------------------+ + |zulu |26.3 usec |21.9 usec |25 usec |24.2 usec |24.9 usec |25.1 usec |N/A |248.8x | + +--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+--------------------------------------------------+ + |aniso8601 |28 usec |25.4 usec |30.2 usec |29.7 usec |31.4 usec |33.8 usec |39.2 usec |264.4x | + +--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+--------------------------------------------------+ + |maya |N/A |36.5 usec |41.3 usec |41.3 usec |40.7 usec |42.3 usec |N/A |376.1x | + +--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+--------------------------------------------------+ + |python-dateutil |70.4 usec |64.4 usec |78.1 usec |78 usec |79.3 usec |83.3 usec |100 usec |664.3x | + +--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+--------------------------------------------------+ + |arrow |74.1 usec |63.5 usec |75 usec |74 usec |74.7 usec |80.9 usec |148 usec |699.8x | + +--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+--------------------------------------------------+ + |metomi-isodatetime |1.24 msec |1.33 msec |1.73 msec |1.73 msec |1.73 msec |1.86 msec |N/A |11719.3x | + +--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+--------------------------------------------------+ + |moment |**Incorrect Result** (``None``)|**Incorrect Result** (``None``)|**Incorrect Result** (``None``)|**Incorrect Result** (``None``)|**Incorrect Result** (``None``)|**Incorrect Result** (``None``)|N/A |2116377.5x | + +--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+--------------------------------------------------+ + +ciso8601 takes 106 nsec, which is **1.9x faster than datetime (builtin)**, the next fastest Python 3.12 parser in this comparison. .. .. -Tested on Linux 5.15.49-linuxkit using the following modules: +Tested on Darwin 22.5.0 using the following modules: .. code:: python aniso8601==9.0.1 - arrow==0.17.0 (on Python 2.7), arrow==1.2.3 (on Python 3.7, 3.8, 3.9, 3.10, 3.11) - backports.datetime_fromisoformat==2.0.0 + arrow==1.3.0 (on Python 3.8, 3.9, 3.10, 3.11, 3.12), arrow==1.2.3 (on Python 3.7), arrow==0.17.0 (on Python 2.7) + backports.datetime_fromisoformat==2.0.1 ciso8601==2.3.0 - iso8601==0.1.16 (on Python 2.7), iso8601==1.1.0 (on Python 3.7, 3.8, 3.9, 3.10, 3.11) + iso8601==2.1.0 (on Python 3.8, 3.9, 3.10, 3.11, 3.12), iso8601==0.1.16 (on Python 2.7) iso8601utils==0.1.2 isodate==0.6.1 maya==0.6.1 - metomi-isodatetime==1!3.0.0 + metomi-isodatetime==1!3.1.0 moment==0.12.1 pendulum==2.1.2 PySO8601==0.2.0 diff --git a/benchmarking/format_results.py b/benchmarking/format_results.py index 1bdb3d0..4c5b21d 100644 --- a/benchmarking/format_results.py +++ b/benchmarking/format_results.py @@ -128,8 +128,8 @@ def write_benchmarking_results(results_directory, output_file, baseline_module, writer = pytablewriter.RstGridTableWriter() formatted_python_versions = [f"Python {major}.{minor}" for major, minor in python_versions_by_modernity] - writer.header_list = ["Module"] + (["Call"] if include_call else []) + formatted_python_versions + [f"Relative slowdown (versus {baseline_module}, latest Python)"] - writer.type_hint_list = [pytablewriter.String] * len(writer.header_list) + writer.headers = ["Module"] + (["Call"] if include_call else []) + formatted_python_versions + [f"Relative slowdown (versus {baseline_module}, latest Python)"] + writer.type_hints = [pytablewriter.String] * len(writer.headers) calling_codes = [calling_code[module] for module in modules_by_modern_speed] performance_results = [[results[module].get(python_version, NOT_APPLICABLE) for python_version in python_versions_by_modernity] for module in modules_by_modern_speed] diff --git a/benchmarking/perform_comparison.py b/benchmarking/perform_comparison.py index bba7115..8b595c3 100644 --- a/benchmarking/perform_comparison.py +++ b/benchmarking/perform_comparison.py @@ -23,7 +23,6 @@ "python-dateutil": ("import dateutil.parser", "dateutil.parser.parse('{timestamp}')"), "iso8601": ("import iso8601", "iso8601.parse_date('{timestamp}')"), "isodate": ("import isodate", "isodate.parse_datetime('{timestamp}')"), - "pendulum": ("from pendulum.parsing import parse_iso8601", "parse_iso8601('{timestamp}')"), "PySO8601": ("import PySO8601", "PySO8601.parse('{timestamp}')"), "str2date": ("from str2date import str2date", "str2date('{timestamp}')"), } @@ -60,10 +59,15 @@ # `arrow` no longer supports Python 3.4 ISO_8601_MODULES["arrow"] = ("import arrow", "arrow.get('{timestamp}').datetime") -if sys.version_info.major >= 3: +if sys.version_info.major >= 3 and (sys.version_info.major, sys.version_info.minor) < (3, 12): # `maya` uses a version of `regex` which no longer supports Python 2 + # `maya` uses `pendulum`, which doesn't yet support Python 3.12 ISO_8601_MODULES["maya"] = ("import maya", "maya.parse('{timestamp}').datetime()") +if (sys.version_info.major, sys.version_info.minor) < (3, 12): + # `pendulum` doesn't yet support Python 3.12 + ISO_8601_MODULES["pendulum"] = ("from pendulum.parsing import parse_iso8601", "parse_iso8601('{timestamp}')") + if (sys.version_info.major, sys.version_info.minor) >= (3, 5): # `moment` is built on `times`, which is built on `arrow`, which no longer supports Python 3.4 # `moment` uses a version of `regex` which no longer supports Python 2 diff --git a/benchmarking/tox.ini b/benchmarking/tox.ini index e3f5c48..08561ac 100644 --- a/benchmarking/tox.ini +++ b/benchmarking/tox.ini @@ -26,12 +26,14 @@ deps= iso8601utils; python_version != '3.6' and python_version != '3.10' isodate ; `maya` uses a version of `regex` which no longer supports Python 2 - maya; python_version > '3' + ; `maya` uses `pendulum`, which doesn't yet support Python 3.12 + maya; python_version > '3' and python_version < '3.12' metomi-isodatetime; python_version >= '3.5' ; `moment` is built on `times`, which is built on `arrow`, which no longer supports Python 3.4 ; `moment` uses a version of `regex` which no longer supports Python 2 moment; python_version >= '3.5' - pendulum + ; `pendulum` doesn't yet support Python 3.12 + pendulum; python_version < '3.12' pyso8601 python-dateutil str2date From a8357c0f2b23f019f002b565205697b59b94d0e3 Mon Sep 17 00:00:00 2001 From: Michael Overmeyer Date: Mon, 16 Oct 2023 14:38:51 -0400 Subject: [PATCH 2/3] Drop `tox`-unsupported Python versions from benchmarking --- benchmarking/tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmarking/tox.ini b/benchmarking/tox.ini index 08561ac..327eed7 100644 --- a/benchmarking/tox.ini +++ b/benchmarking/tox.ini @@ -1,7 +1,7 @@ [tox] requires = tox>=4 -envlist = py312,py311,py310,py39,py38,py37,py36,py35,py34,py27 +envlist = py312,py311,py310,py39,py38,py37 setupdir=.. [testenv] From 90543e804a6e57fbb26e546426d778fcfe592583 Mon Sep 17 00:00:00 2001 From: Michael Overmeyer Date: Mon, 16 Oct 2023 15:53:12 -0400 Subject: [PATCH 3/3] Shorten the error message in cases of incorrect parsing --- README.rst | 6 +++--- benchmarking/format_results.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index 8173e67..30f2e7d 100644 --- a/README.rst +++ b/README.rst @@ -94,7 +94,7 @@ Parsing a timestamp with no time zone information (e.g., ``2014-01-09T21:48:00`` +--------------------------------+-----------+-----------+-----------+----------+----------+----------+-------------------------------+--------------------------------------------------+ |udatetime |709 nsec |677 nsec |692 nsec |715 nsec |705 nsec |700 nsec |586 nsec |7.5x | +--------------------------------+-----------+-----------+-----------+----------+----------+----------+-------------------------------+--------------------------------------------------+ - |str2date |6.84 usec |5.8 usec |6.86 usec |6.6 usec |6.47 usec |6.89 usec |**Incorrect Result** (``None``)|72.5x | + |str2date |6.84 usec |5.8 usec |6.86 usec |6.6 usec |6.47 usec |6.89 usec |❌ |72.5x | +--------------------------------+-----------+-----------+-----------+----------+----------+----------+-------------------------------+--------------------------------------------------+ |iso8601utils |N/A |N/A |N/A |8.64 usec |8.69 usec |9.2 usec |11.2 usec |74.0x | +--------------------------------+-----------+-----------+-----------+----------+----------+----------+-------------------------------+--------------------------------------------------+ @@ -142,7 +142,7 @@ Parsing a timestamp with time zone information (e.g., ``2014-01-09T21:48:00-05:3 +--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+--------------------------------------------------+ |udatetime |828 nsec |785 nsec |805 nsec |811 nsec |798 nsec |816 nsec |768 nsec |7.8x | +--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+--------------------------------------------------+ - |str2date |7.79 usec |6.86 usec |7.71 usec |7.77 usec |7.62 usec |8 usec |**Incorrect Result** (``None``)|73.6x | + |str2date |7.79 usec |6.86 usec |7.71 usec |7.77 usec |7.62 usec |8 usec |❌ |73.6x | +--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+--------------------------------------------------+ |iso8601 |12.9 usec |11.6 usec |13.1 usec |12.4 usec |12.9 usec |12.6 usec |31.1 usec |121.7x | +--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+--------------------------------------------------+ @@ -164,7 +164,7 @@ Parsing a timestamp with time zone information (e.g., ``2014-01-09T21:48:00-05:3 +--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+--------------------------------------------------+ |metomi-isodatetime |1.24 msec |1.33 msec |1.73 msec |1.73 msec |1.73 msec |1.86 msec |N/A |11719.3x | +--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+--------------------------------------------------+ - |moment |**Incorrect Result** (``None``)|**Incorrect Result** (``None``)|**Incorrect Result** (``None``)|**Incorrect Result** (``None``)|**Incorrect Result** (``None``)|**Incorrect Result** (``None``)|N/A |2116377.5x | + |moment |❌ |❌ |❌ |❌ |❌ |❌ |N/A |2116377.5x | +--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+--------------------------------------------------+ ciso8601 takes 106 nsec, which is **1.9x faster than datetime (builtin)**, the next fastest Python 3.12 parser in this comparison. diff --git a/benchmarking/format_results.py b/benchmarking/format_results.py index 4c5b21d..aadf7f1 100644 --- a/benchmarking/format_results.py +++ b/benchmarking/format_results.py @@ -23,7 +23,7 @@ def __str__(self): if self.exception: return f"Raised ``{self.exception}`` Exception" elif not self.matched_expected: - return f"**Incorrect Result** (``{self.parsed_value}``)" + return "❌" else: return self.formatted_timing()