-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark.py
124 lines (93 loc) · 3.59 KB
/
benchmark.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/bin/python
import os
import sys
import random
import time
from timeit import timeit
import subprocess
import shutil
import string
import ptaglib
N = int(sys.argv[1])
if os.path.exists("benchmark_dir"): shutil.rmtree("benchmark_dir")
os.mkdir("benchmark_dir")
os.chdir("benchmark_dir")
log = open('../benchmark_log.txt','w')
log.write("Making "+str(N)+" randomly tagged files...\n")
log.close();del log
log = open('../benchmark_log.txt','a')
t = synclib.synctag(".tags")
start = time.time()
# make N files with some random tags
for i in range(0,N):
f = open(str(i)+".txt", 'w')
f.write(str(random.randint(1,1000)))
f.close(); del f
tags = random.sample(string.ascii_letters,5)
metas = { "author":random.choice(["andy","john","bukowski","ronald","buck"]), "year":random.choice(["2017","2018","2019"])}
try:
t.addfile(str(i)+".txt", tags=tags, meta=metas)
except Exception as err: print(err)
t.update_file()
#for j in range(0,4):
# subprocess.call(["python", "../synctag.py", "add", random.choice(string.ascii_letters), str(i)+".txt"])
#subprocess.call(["python", "../synctag.py", "add", "author:"+random.choice(["andy","john","bukowski","ronald","buck"]), str(i)+".txt"])
#subprocess.call(["python", "../synctag.py", "add", "year:"+random.choice(["1999","2000","2001"]), str(i)+".txt"])
log.write("Wrote and tagged files in {:10.6f} seconds. Running tests...\n".format(time.time() - start))
print("Wrote and tagged files in {:10.6f} seconds. Running tests...\n".format(time.time() - start))
log.close();del log
log = open('../benchmark_log.txt','a')
# time some queries
start = time.time()
subprocess.call(["python", "../synctag.py", "search", "a"])
runtime = "'a' search: {:10.6f} seconds\n".format(time.time() - start)
log.write(runtime)
print(runtime)
log.close();del log
log = open('../benchmark_log.txt','a')
start = time.time()
subprocess.call(["python", "../synctag.py", "search", "author:andy"])
runtime = "author:andy search: {:10.6f} seconds\n".format(time.time() - start)
log.write(runtime)
print(runtime)
log.close();del log
log = open('../benchmark_log.txt','a')
start = time.time()
subprocess.call(["python", "../synctag.py", "search", "(a or b)"])
runtime = "a or b search: {:10.6f} seconds\n".format(time.time() - start)
log.write(runtime)
print(runtime)
log.close();del log
log = open('../benchmark_log.txt','a')
start = time.time()
subprocess.call(["python", "../synctag.py", "search", "(a and b)"])
runtime = "a and b search: {:10.6f} seconds\n".format(time.time() - start)
log.write(runtime)
print(runtime)
log.close();del log
log = open('../benchmark_log.txt','a')
start = time.time()
subprocess.call(["python", "../synctag.py", "search", "((a and b) or c)"])
runtime = "((a and b) or c) search: {:10.6f} seconds\n".format(time.time() - start)
log.write(runtime)
print(runtime)
log.close();del log
log = open('../benchmark_log.txt','a')
start = time.time()
subprocess.call(["python", "../synctag.py", "search", "(not a)"])
runtime = "not a search: {:10.6f} seconds\n".format(time.time() - start)
log.write(runtime)
print(runtime)
log.close();del log
log = open('../benchmark_log.txt','a')
start = time.time()
subprocess.call(["python", "../synctag.py", "search", "(((not author:andy) and (not b)) or (b and (not c)))"])
runtime = "big search: {:10.6f} seconds\n".format(time.time() - start)
log.write(runtime)
print(runtime)
log.close();del log
log = open('../benchmark_log.txt','a')
print("ok test\n")
print( timeit(stmt ='subprocess.call(["python", "../synctag.py", "search", "(((not author:andy) and (not b)) or (b and (not c)))"])', setup="import subprocess", number=1))
log.close()
del log