Skip to content

Instantly share code, notes, and snippets.

@DimanNe
Created November 6, 2021 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DimanNe/0e8683caf75340e13c733f08563388ba to your computer and use it in GitHub Desktop.
Save DimanNe/0e8683caf75340e13c733f08563388ba to your computer and use it in GitHub Desktop.
import fileinput
from datetime import datetime
import itertools as itl
def nwise(iterable, n=2):
iters = itl.tee(iterable, n)
for i, it in enumerate(iters):
next(itl.islice(it, i, i), None)
return zip(*iters)
first_time = None
fmt = '%H:%M:%S.%f'
for curr, nxt in nwise(fileinput.input(), 2):
# print(f'curr: {curr}')
# print(f'next: {nxt}')
try:
curr_time = datetime.strptime(curr.split()[0], fmt)
next_time = datetime.strptime(nxt.split()[0], fmt)
if not first_time:
first_time = curr_time
prev_str_time = first_time
diff_since_start = curr_time - first_time
this_cmd_duration = next_time - curr_time
print(f'{round(diff_since_start.total_seconds() * 1000, 3):.3f} / {round(this_cmd_duration.total_seconds() * 1000, 3):.3f} ms: {curr}', end='')
except:
print(f'{curr}', end='')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment