Skip to content

Instantly share code, notes, and snippets.

@kylegallatin
Created July 28, 2022 14:34
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 kylegallatin/6fea75fc58ba053fbceb03941a1834d2 to your computer and use it in GitHub Desktop.
Save kylegallatin/6fea75fc58ba053fbceb03941a1834d2 to your computer and use it in GitHub Desktop.
import time
class PerformanceMonitor:
def __init__(self):
self.inference_times = []
def record(self, prediction_time: float) -> None:
self.inference_times.append(prediction_time)
def mean(self) -> float:
return sum(self.inference_times)/len(self.inference_times)
def model_predict(user_id: str) -> float:
start = time.time()
model = load_latest_model()
features = feature_store.get_user_feature(user_id)
prediction = model.predict([[v for k,v in features.items() if k != "target"]])
end = time.time()
monitor.record(end-start)
return prediction
monitor = PerformanceMonitor()
model_predict("a27b0912-0cf8-11ed-899e-b29c4abd48f4")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment