Last active
December 21, 2021 11:40
-
-
Save mmazur/c813d12b7e01ad24271e5ba8852294d7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/python3 | |
import numpy as np | |
from time import perf_counter | |
from pandas import to_datetime, Series | |
from datetime import datetime | |
fromtimestamp = datetime.fromtimestamp | |
rng = np.random.default_rng() | |
ints = Series(rng.integers(1, 1640084533, 200000)) | |
slow_start = perf_counter() | |
slow = ints.apply(lambda ts: to_datetime(ts, unit="s")) | |
slow_stop = perf_counter() | |
fast_start = perf_counter() | |
fast = ints.apply(lambda ts: fromtimestamp(ts)) | |
fast_stop = perf_counter() | |
print(f"Slow: {slow_stop-slow_start}\nFast: {fast_stop-fast_start}") | |
# Outcome; | |
# [mmazur@klapek ~]$ ./test.py | |
# Slow: 21.08506918803323 | |
# Fast: 0.16851535497698933 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment