Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions cache_magic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import pickle
import os
import time
import hashlib
import datetime
import shutil
Expand Down Expand Up @@ -118,7 +119,11 @@ def _create_new_value(self, shell, var_folder_path, var_data_path, var_info_path

# calculate the new Value in user-context
cmd = self._reconstruct_expression(var_name, var_value)

# time the shell command
start_time = time.time()
result = shell.run_cell(cmd)
compute_time = time.time() - start_time

if not result.success:
raise CacheCallException(
Expand All @@ -131,7 +136,8 @@ def _create_new_value(self, shell, var_folder_path, var_data_path, var_info_path

info = dict(expression_hash=self.hash_line(var_value),
store_date=datetime.datetime.now(),
version=version)
version=version,
compute_time=compute_time)

with open(var_info_path, 'wb') as fp:
pickle.dump(info, fp)
Expand All @@ -153,12 +159,15 @@ def _show_all(base_dir):

try:
info = CacheCall.get_from_file(var_info_path)
vars.append([var_name, size, info["store_date"], info["version"], info["expression_hash"]])
vars.append([var_name, size, info["store_date"],
"%.1f" % info.get("compute_time", 0.0),
info["version"], info["expression_hash"]])

except IOError:
print("Warning: failed to read info variable '" + var_name + "'")

display(HTML(tabulate(vars, headers=["var name", "size(byte)", "stored at date", "version", "expression(hash)"],
display(HTML(tabulate(vars, headers=["var name", "size(byte)", "stored at date",
"time(s)", "version", "expression(hash)"],
tablefmt="html")))

@staticmethod
Expand Down