Last active
March 14, 2023 22:15
-
-
Save almarklein/20640253fe54fc35d4a4c6dfcc1ad625 to your computer and use it in GitHub Desktop.
timestamp speed and precision
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
from datetime import datetime | |
import numpy as np | |
import time | |
n = 100000 | |
mark1 = datetime.now() | |
t0 = time.perf_counter() | |
count = 0 | |
for i in range(n): | |
mark2 = datetime.now() | |
if mark1 < mark2: | |
mark1 = mark2 | |
count += 1 | |
print(time.perf_counter() - t0, count) | |
mark1 = np.datetime64(datetime.now()) | |
t0 = time.perf_counter() | |
count = 0 | |
for i in range(n): | |
mark2 = np.datetime64(datetime.now()) | |
if mark1 < mark2: | |
mark1 = mark2 | |
count += 1 | |
print(time.perf_counter() - t0, count) | |
mark1 = time.time() | |
t0 = time.perf_counter() | |
count = 0 | |
for i in range(n): | |
mark2 = time.time() | |
if mark1 < mark2: | |
mark1 = mark2 | |
count += 1 | |
print(time.perf_counter() - t0, count) | |
mark1 = time.perf_counter_ns() | |
t0 = time.perf_counter() | |
count = 0 | |
for i in range(n): | |
mark2 = time.perf_counter_ns() | |
if mark1 < mark2: | |
mark1 = mark2 | |
count += 1 | |
print(time.perf_counter() - t0, count) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
On my machine: