Skip to content

Instantly share code, notes, and snippets.

@gavinsykes
Created July 5, 2021 14:13
Show Gist options
  • Save gavinsykes/7ee06ad9cb835db98c0f5f319b46a8cb to your computer and use it in GitHub Desktop.
Save gavinsykes/7ee06ad9cb835db98c0f5f319b46a8cb to your computer and use it in GitHub Desktop.
def fullprint(challenge,fun,arg,filepath):
import time
import csv
import platform
import psutil
import sys
timing = {}
timing['start'] = time.time()
if arg:
result = fun(arg)
else:
result = fun()
timing['finish'] = time.time()
print(challenge.format(arg))
print(f'Start time: {timing["start"]}')
print(f'Result: {result}')
print(f'End time: {timing["finish"]}')
print(f'This returns {result} in {timing["finish"]-timing["start"]} seconds!')
py_v = sys.version_info
uname = platform.uname()
cpu = psutil.cpu_freq()
mem = psutil.virtual_memory()
with open(f'{filepath.split(".")[0]}_timings.csv', 'a', newline='') as tcsv:
twriter = csv.writer(tcsv, delimiter = ',', quotechar = '"', quoting = csv.QUOTE_MINIMAL)
twriter.writerow(['Python',f'{py_v.major}.{py_v.minor}.{py_v.micro}',arg,timing['finish'] - timing['start'],uname.system,uname.release,uname.version,uname.machine,uname.processor,cpu.current,mem.total,timing['start']])
tcsv.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment