summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2019-02-16 16:19:20 +0200
committerLars Wirzenius <liw@liw.fi>2019-02-16 16:19:20 +0200
commitb89ea860741543e93101f851591606ae88743093 (patch)
tree78be784525966604dde5833b4dd5c8258738b09b
parentb49c7cb1c42f21ca9a1eeeeb9621e05d87ba5887 (diff)
downloadmuck-poc-b89ea860741543e93101f851591606ae88743093.tar.gz
Fix: log file benchmark time measurement and reporting
-rwxr-xr-xdummy-logger29
1 files changed, 14 insertions, 15 deletions
diff --git a/dummy-logger b/dummy-logger
index 10d08f7..ae53d35 100755
--- a/dummy-logger
+++ b/dummy-logger
@@ -45,6 +45,9 @@ def store_snippet(url, token, i, snippet):
r = requests.post(url, headers=headers, data=json.dumps(obj))
assert r.ok
+def create_snippets(url, token, n):
+ for i, snippet in enumerate(generate_snippets(n)):
+ store_snippet(url, token, i, snippet)
def get_snippet(url, token, rid):
url = '{}/res'.format(url)
@@ -85,28 +88,24 @@ def get_full_log(url, token, ids):
snippets.sort(key=lambda o: o['seq'])
return ''.join(o['text'] for o in snippets)
-def report(msg, started):
+def measure(func):
+ started = time.time()
+ ret = func()
now = time.time()
- duration = now - started
- print(msg)
- return duration
-
+ return now - started, ret
+
url = sys.argv[1]
token = sys.argv[2]
N = int(sys.argv[3])
-started = time.time()
-_ = report('creating snippets', started)
-for i, snippet in enumerate(generate_snippets(N)):
- store_snippet(url, token, i, snippet)
-
-creation_secs = report('getting snippets', started)
-ids = get_snippet_ids(url, token)
+print('creating snippets')
+creation_secs, _ = measure(lambda: create_snippets(url, token, N))
-get_snippets_secs = report('getting full log', started)
+print('getting list of snippets')
+get_snippets_secs, ids = measure(lambda: get_snippet_ids(url, token))
-log = get_full_log(url, token, ids)
-get_log_secs = report('checking', started)
+print('reconstructing full log')
+get_log_secs, log = measure(lambda: get_full_log(url, token, ids))
expected = full_log(N)
if expected != log: