Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions py/competitors.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def select(TS, U, Cg):
s, uncs_s = ui, uncs
return s

ptime_start = time.clock()
ptime_start = time.perf_counter()

TCS = loadTestSuite(input_file)
TS = OrderedDict(sorted(TCS.items(), key=lambda t: -len(t[1])))
Expand Down Expand Up @@ -99,7 +99,7 @@ def select(TS, U, Cg):
Cg = Cg | U[s]
del U[s]

ptime = time.clock() - ptime_start
ptime = time.perf_counter() - ptime_start

return 0.0, ptime, P[1:]

Expand All @@ -114,7 +114,7 @@ def select(TS, U, Cg):
s, uncs_s = ui, uncs
return s

ptime_start = time.clock()
ptime_start = time.perf_counter()

TCS = loadTestSuite(input_file)
TS = OrderedDict(sorted(TCS.items(), key=lambda t: -len(t[1])))
Expand All @@ -136,7 +136,7 @@ def select(TS, U, Cg):
Cg = Cg | U[s]
del U[s]

ptime = time.clock() - ptime_start
ptime = time.perf_counter() - ptime_start

return 0.0, ptime, P[1:]

Expand Down Expand Up @@ -173,7 +173,7 @@ def select(TS, P, C):

# # # # # # # # # # # # # # # # # # # # # #

ptime_start = time.clock()
ptime_start = time.perf_counter()

TS = loadTestSuite(input_file)

Expand Down Expand Up @@ -208,7 +208,7 @@ def select(TS, P, C):
del U[s]
C = C - set([s])

ptime = time.clock() - ptime_start
ptime = time.perf_counter() - ptime_start

return 0.0, ptime, P[1:]

Expand Down Expand Up @@ -243,7 +243,7 @@ def select(TS, P, C):

# # # # # # # # # # # # # # # # # # # # # #

ptime_start = time.clock()
ptime_start = time.perf_counter()

TS = loadTestSuite(input_file)

Expand Down Expand Up @@ -283,7 +283,7 @@ def select(TS, P, C):
del U[s]
C = C - set([s])

ptime = time.clock() - ptime_start
ptime = time.perf_counter() - ptime_start

return 0.0, ptime, P[1:]

Expand Down Expand Up @@ -326,7 +326,7 @@ def select(TS, P, C):

# # # # # # # # # # # # # # # # # # # # # #

ptime_start = time.clock()
ptime_start = time.perf_counter()

TS = loadTestSuite(input_file)

Expand Down Expand Up @@ -361,7 +361,7 @@ def select(TS, P, C):
del U[s]
C = C - set([s])

ptime = time.clock() - ptime_start
ptime = time.perf_counter() - ptime_start

return 0.0, ptime, P[1:]

Expand Down Expand Up @@ -401,7 +401,7 @@ def select(TS, P, C):

# # # # # # # # # # # # # # # # # # # # # #

ptime_start = time.clock()
ptime_start = time.perf_counter()

TS = loadTestSuite(input_file)

Expand Down Expand Up @@ -441,7 +441,7 @@ def select(TS, P, C):
del U[s]
C = C - set([s])

ptime = time.clock() - ptime_start
ptime = time.perf_counter() - ptime_start

return 0.0, ptime, P[1:]

56 changes: 28 additions & 28 deletions py/fastr.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ def storeSignatures(input_file, sigfile, hashes, bbox=False, k=5):
# load stored signatures
def loadSignatures(input_file):
sig = {}
start = time.clock()
start = time.perf_counter()
with open(input_file, "r") as fin:
tcID = 1
for tc in fin:
sig[tcID] = [i.strip() for i in tc[:-1].split()]
tcID += 1
return sig, time.clock() - start
return sig, time.perf_counter() - start


# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Expand All @@ -105,27 +105,27 @@ def fast_pw(input_file, r, b, bbox=False, k=5, memory=False, B=0):
if memory:
test_suite = loadTestSuite(input_file, bbox=bbox, k=k)
# generate minhashes signatures
mh_t = time.clock()
mh_t = time.perf_counter()
tcs_minhashes = {tc[0]: lsh.tcMinhashing(tc, hashes)
for tc in test_suite.items()}
mh_time = time.clock() - mh_t
ptime_start = time.clock()
mh_time = time.perf_counter() - mh_t
ptime_start = time.perf_counter()

else:
# loading input file and generating minhashes signatures
sigfile = input_file.replace(".txt", ".sig")
sigtimefile = "{}_sigtime.txt".format(input_file.split(".")[0])
if not os.path.exists(sigfile):
mh_t = time.clock()
mh_t = time.perf_counter()
storeSignatures(input_file, sigfile, hashes, bbox, k)
mh_time = time.clock() - mh_t
mh_time = time.perf_counter() - mh_t
with open(sigtimefile, "w") as fout:
fout.write(repr(mh_time))
else:
with open(sigtimefile, "r") as fin:
mh_time = eval(fin.read().replace("\n", ""))

ptime_start = time.clock()
ptime_start = time.perf_counter()
tcs_minhashes, load_time = loadSignatures(sigfile)

tcs = set(tcs_minhashes.keys())
Expand Down Expand Up @@ -199,7 +199,7 @@ def fast_pw(input_file, r, b, bbox=False, k=5, memory=False, B=0):
tcs -= set([selected_tc])
del tcs_minhashes[selected_tc]

ptime = time.clock() - ptime_start
ptime = time.perf_counter() - ptime_start

max_ts_size = sum((1 for line in open(input_file)))
return mh_time, ptime, prioritized_tcs[1:max_ts_size]
Expand All @@ -216,27 +216,27 @@ def fast_(input_file, selsize, r, b, bbox=False, k=5, memory=False, B=0):
if memory:
test_suite = loadTestSuite(input_file, bbox=bbox, k=k)
# generate minhashes signatures
mh_t = time.clock()
mh_t = time.perf_counter()
tcs_minhashes = {tc[0]: lsh.tcMinhashing(tc, hashes)
for tc in test_suite.items()}
mh_time = time.clock() - mh_t
ptime_start = time.clock()
mh_time = time.perf_counter() - mh_t
ptime_start = time.perf_counter()

else:
# loading input file and generating minhashes signatures
sigfile = input_file.replace(".txt", ".sig")
sigtimefile = "{}_sigtime.txt".format(input_file.split(".")[0])
if not os.path.exists(sigfile):
mh_t = time.clock()
mh_t = time.perf_counter()
storeSignatures(input_file, sigfile, hashes, bbox, k)
mh_time = time.clock() - mh_t
mh_time = time.perf_counter() - mh_t
with open(sigtimefile, "w") as fout:
fout.write(repr(mh_time))
else:
with open(sigtimefile, "r") as fin:
mh_time = eval(fin.read().replace("\n", ""))

ptime_start = time.clock()
ptime_start = time.perf_counter()
tcs_minhashes, load_time = loadSignatures(sigfile)

tcs = set(tcs_minhashes.keys())
Expand Down Expand Up @@ -310,7 +310,7 @@ def fast_(input_file, selsize, r, b, bbox=False, k=5, memory=False, B=0):
if len(prioritized_tcs) >= B+1:
break

ptime = time.clock() - ptime_start
ptime = time.perf_counter() - ptime_start

max_ts_size = sum((1 for line in open(input_file)))
return mh_time, ptime, prioritized_tcs[1:max_ts_size]
Expand Down Expand Up @@ -407,16 +407,16 @@ def reductionPlusPlus(TS, B):
# Returns: preparation time, reduction time, reduced test suite
def fastPlusPlus(inputFile, dim=0, B=0, memory=True):
if memory:
t0 = time.clock()
t0 = time.perf_counter()
TS = preparation(inputFile, dim=dim)
t1 = time.clock()
t1 = time.perf_counter()
pTime = t1-t0
else:
rpFile = inputFile.replace(".txt", ".rp")
if not os.path.exists(rpFile):
t0 = time.clock()
t0 = time.perf_counter()
TS = preparation(inputFile, dim=dim)
t1 = time.clock()
t1 = time.perf_counter()
pTime = t1-t0
pickle.dump((pTime, TS), open(rpFile, "wb"))
else:
Expand All @@ -425,9 +425,9 @@ def fastPlusPlus(inputFile, dim=0, B=0, memory=True):
if B <= 0:
B = len(TS)

t2 = time.clock()
t2 = time.perf_counter()
reducedTS = reductionPlusPlus(TS, B)
t3 = time.clock()
t3 = time.perf_counter()
sTime = t3-t2

return pTime, sTime, reducedTS
Expand Down Expand Up @@ -478,16 +478,16 @@ def reductionCS(TS, B):
# Returns: preparation time, reduction time, reduced test suite
def fastCS(inputFile, dim=0, B=0, memory=True):
if memory:
t0 = time.clock()
t0 = time.perf_counter()
TS = preparation(inputFile, dim=dim)
t1 = time.clock()
t1 = time.perf_counter()
pTime = t1-t0
else:
rpFile = inputFile.replace(".txt", ".rp")
if not os.path.exists(rpFile):
t0 = time.clock()
t0 = time.perf_counter()
TS = preparation(inputFile, dim=dim)
t1 = time.clock()
t1 = time.perf_counter()
pTime = t1-t0
pickle.dump((pTime, TS), open(rpFile, "wb"))
else:
Expand All @@ -496,9 +496,9 @@ def fastCS(inputFile, dim=0, B=0, memory=True):
if B <= 0:
B = len(TS)

t2 = time.clock()
t2 = time.perf_counter()
reducedTS = reductionCS(TS, B)
t3 = time.clock()
t3 = time.perf_counter()
sTime = t3-t2

return pTime, sTime, reducedTS
Loading