Skip to content

Improve timestamp handling

Explanation of changes

Improve performance of TUID timestamp parsing and fix a bug where part of the milliseconds content was not parsed.

Motivation of changes

Benchmark:

import datetime
from quantify_core.data.handling import gen_tuid, TUID
tuid = gen_tuid()
print(tuid, TUID.datetime(tuid))

%timeit datetime.datetime.strptime(tuid[:18], "%Y%m%d-%H%M%S-%f")
%timeit datetime.datetime.fromisoformat(tuid[:15]) + datetime.timedelta(milliseconds=int(tuid[16:19]))
# 20250415-114533-522-c40c74 2025-04-15 11:45:33.520000
# 8.12 μs ± 546 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)
# 1.09 μs ± 127 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)

(the timestamp parsing is a significant part of the computation time when scanning through all datasets on disk)


Merge checklist

See also merge request guidelines

  • Merge request has been reviewed (in-depth by a knowledgeable contributor), and is approved by a project maintainer.
  • New code is covered by unit tests (or N/A).
  • [N/A] New code is documented and docstrings use numpydoc format (or N/A).
  • [N/A] New functionality: considered making private instead of extending public API (or N/A).
  • Public API changed: milliseconds part of tuid is now parsed into the timestamp
  • [N/A] Newly added/adjusted documentation and docstrings render properly (or N/A).
  • [N/A] Pipeline fix or dependency update: post in #software-for-developers channel to merge main back in or update local packages (or N/A).
  • [N/A] Tested on hardware (or N/A).
  • [N/A] AUTHORS.md has been updated (or N/A).
  • Windows tests in CI pipeline pass (manually triggered by maintainers before merging).
    • Maintainers do not hit Auto-merge, we need to actively check as manual tests do not block pipeline

For reference, the issues workflow is described in the contribution guidelines.

Edited by Olga Lebiga

Merge request reports

Loading