#!/usr/bin/env python3 import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt import numpy as np import json from argparse import ArgumentParser """ Plots graph of latencies of memgraph and neo4j. Takes paths to json of latencies as arguments. """ def main(): argp = ArgumentParser(description=__doc__) argp.add_argument('--memgraph-latency', help='Path to the json of memgraph latency') argp.add_argument('--neo4j-latency', help='Path to the json of neo4j latency') args = argp.parse_args() fig = plt.gcf() fig.set_size_inches(10, 16) with open(args.neo4j_latency) as json_file: json_neo = json.load(json_file) with open(args.memgraph_latency) as json_file: json_mem = json.load(json_file) tests_num = 0 time_list_neo = [] time_list_mem = [] max_time = 0 for key in json_mem['data']: if json_neo['data'][key]['status'] == "passed" and \ json_mem['data'][key]['status'] == 'passed': time_neo = json_neo['data'][key]['execution_time'] time_mem = json_mem['data'][key]['execution_time'] max_time = max(max_time, time_neo, time_mem) offset = 0.01 * max_time for key in json_mem['data']: if json_neo['data'][key]['status'] == "passed" and \ json_mem['data'][key]['status'] == 'passed': time_neo = json_neo['data'][key]['execution_time'] time_mem = json_mem['data'][key]['execution_time'] time_list_neo.append(time_neo) time_list_mem.append(time_mem) tests_num += 1 if time_neo < time_mem: plt.plot((time_mem, time_neo), (tests_num, tests_num), color='red', label=key, lw=0.3) else: plt.plot((time_mem, time_neo), (tests_num, tests_num), color='green', label=key, lw=0.3) ratio = '%.2f' % (max(time_neo, time_mem) / min(time_neo, time_mem)) plt.text(max(time_mem, time_neo) + offset, tests_num, key + " ---> " + \ ratio + "x", size=1) x = range(1, tests_num + 1) plt.plot(time_list_mem, x, marker='o', markerfacecolor='orange', color='orange', linestyle='', markersize=0.5) plt.plot(time_list_neo, x, marker='o', markerfacecolor='blue', color='blue', linestyle='', markersize=0.5) plt.margins(0.1, 0.01) plt.savefig("latency_graph.png", dpi=2000) if __name__ == '__main__': main()