Skip to content

Instantly share code, notes, and snippets.

@DalyaG
Last active April 22, 2020 07:04
Show Gist options
  • Save DalyaG/993e80cac73dc9b9ebd6bc5e7977dfc3 to your computer and use it in GitHub Desktop.
Save DalyaG/993e80cac73dc9b9ebd6bc5e7977dfc3 to your computer and use it in GitHub Desktop.
runtime logger
import os
from time import time
class RuntimeLogger:
def __init__(self, log_dir: str):
self.runtime_filepath = os.path.join(log_dir, "runtime.json")
self.runtime_dict = {}
self.global_start_time = None
def start(self):
self.global_start_time = time()
def log_task_end(self, task_name: str, task_start_time: float):
task_runtime = time() - task_start_time
self.runtime_dict.update({task_name: task_runtime})
def log_experiment_end(self):
self.log_task_end('global_runtime', self.global_start_time)
json.dump(self.runtime_dict,
open(self.runtime_filepath, 'w'), indent=4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment