From c371f06fdea413cfb00aa8f81b7a5535a7ecdbc4 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Tue, 24 Oct 2017 16:55:53 -0700 Subject: [PATCH] Include took_ms in JSON output --- app.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app.py b/app.py index ab332cbb..8ebbc66b 100644 --- a/app.py +++ b/app.py @@ -11,6 +11,7 @@ import json import base64 import hashlib import sys +import time app_root = Path(__file__).parent @@ -95,6 +96,7 @@ class BaseView(HTTPMethodView): except KeyError: as_json = False extra_template_data = {} + start = time.time() try: data, extra_template_data = self.data( request, name, hash, **kwargs @@ -104,6 +106,8 @@ class BaseView(HTTPMethodView): 'ok': False, 'error': str(e), } + end = time.time() + data['took_ms'] = (end - start) * 1000 if as_json: # Special case for .jsono extension if as_json == '.jsono':