forked from gaolk/graph-database-benchmark
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathpg.py
68 lines (60 loc) · 2.24 KB
/
pg.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
############################################################
# Copyright (c) 2015-now, TigerGraph Inc.
# All rights reserved
# It is provided as it is for benchmark reproducible purpose.
# anyone can use it for benchmark purpose with the
# acknowledgement to TigerGraph.
# Author: Mingxi Wu mingxi.wu@tigergraph.com
############################################################
import random
import sys
import os
import datetime
from timeit import default_timer as timer
from query_runner import *
from config import *
###########################################################
# PageRank benchmark
###########################################################
def RunPG(filename, db_name, num_iteration, num_tests, notes = ""):
"""
#test,num_iteration,time
...
summary,num_iteration,average_time
"""
#create result folder
if not os.path.exists(os.path.dirname("./result/")):
try:
os.makedirs(os.path.dirname("./result/"))
except OSError as exc: # Guard against race condition
if exc.errno != errno.EEXIST:
raise
ofile = open("result/PG-latency-" + db_name + "-" + filename, 'a')
if db_name == "neo4j":
runner = Neo4jQueryRunner()
elif db_name == "tigergraph":
runner = TigerGraphQueryRunner()
else:
print("invalid db " + db_name)
total_time = 0.0
total_knsize = 0
report = "\n---------- " + str(datetime.datetime.now()) + " " + notes + " ----------\n"
for i in range(0, num_tests):
start = timer()
runner.PG(num_iteration)
end = timer()
exe_time = end - start
total_time += exe_time
line = str(i) + "," + str(num_iteration) + "," + str(exe_time) + " seconds"
print(line)
report += line + "\n"
report += "summary," + str(num_iteration) + "," + str(total_time/num_tests) + " seconds"
ofile.write(report)
print (report)
if __name__ == "__main__":
# kn.py file_name db_name num_iteration
if len(sys.argv) < 5:
print("Usage: python pg.py raw_file_name db_name num_iteration num_tests")
sys.exit()
# python pg.py graph500-22 neo4j 1 2
RunPG(os.path.basename(sys.argv[1]), sys.argv[2], int(sys.argv[3]), int(sys.argv[4]), sys.argv[5] if len(sys.argv) == 6 else "")