From 99782c7295d6223aba68925b16f60fc2dd1a9de2 Mon Sep 17 00:00:00 2001 From: pranomostro Date: Thu, 19 Nov 2020 13:27:32 +0100 Subject: [PATCH] Replaced the deprecated time.clock() by time.perf_counter(). After the suggestion in https://docs.python.org/3.3/library/time.html#time.clock --- py/competitors.py | 24 +++++++-------- py/fastr.py | 56 +++++++++++++++++----------------- py/fastr_adequate.py | 72 ++++++++++++++++++++++---------------------- 3 files changed, 76 insertions(+), 76 deletions(-) diff --git a/py/competitors.py b/py/competitors.py index 3d7c4698..e56511e1 100644 --- a/py/competitors.py +++ b/py/competitors.py @@ -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]))) @@ -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:] @@ -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]))) @@ -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:] @@ -173,7 +173,7 @@ def select(TS, P, C): # # # # # # # # # # # # # # # # # # # # # # - ptime_start = time.clock() + ptime_start = time.perf_counter() TS = loadTestSuite(input_file) @@ -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:] @@ -243,7 +243,7 @@ def select(TS, P, C): # # # # # # # # # # # # # # # # # # # # # # - ptime_start = time.clock() + ptime_start = time.perf_counter() TS = loadTestSuite(input_file) @@ -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:] @@ -326,7 +326,7 @@ def select(TS, P, C): # # # # # # # # # # # # # # # # # # # # # # - ptime_start = time.clock() + ptime_start = time.perf_counter() TS = loadTestSuite(input_file) @@ -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:] @@ -401,7 +401,7 @@ def select(TS, P, C): # # # # # # # # # # # # # # # # # # # # # # - ptime_start = time.clock() + ptime_start = time.perf_counter() TS = loadTestSuite(input_file) @@ -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:] diff --git a/py/fastr.py b/py/fastr.py index c6b25d40..164daa6e 100644 --- a/py/fastr.py +++ b/py/fastr.py @@ -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 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # @@ -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()) @@ -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] @@ -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()) @@ -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] @@ -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: @@ -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 @@ -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: @@ -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 diff --git a/py/fastr_adequate.py b/py/fastr_adequate.py index 018e37a1..af76480c 100644 --- a/py/fastr_adequate.py +++ b/py/fastr_adequate.py @@ -81,13 +81,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 def loadCoverage(wBoxFile): @@ -105,9 +105,9 @@ def loadCoverage(wBoxFile): def fast_pw(input_file, wBoxFile, r, b, bbox=False, k=5, memory=False): n = r * b # number of hash functions - tC0 = time.clock() + tC0 = time.perf_counter() C = loadCoverage(wBoxFile) - tC1 = time.clock() + tC1 = time.perf_counter() maxCov = reduce(lambda x, y: x | y, C.values()) hashes = [lsh.hashFamily(i) for i in range(n)] @@ -115,27 +115,27 @@ def fast_pw(input_file, wBoxFile, r, b, bbox=False, k=5, memory=False): 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()) @@ -212,7 +212,7 @@ def fast_pw(input_file, wBoxFile, r, b, bbox=False, k=5, memory=False): del tcs_minhashes[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, tC1-tC0, ptime, prioritized_tcs[1:max_ts_size] @@ -224,9 +224,9 @@ def fast_pw(input_file, wBoxFile, r, b, bbox=False, k=5, memory=False): def fast_(input_file, wBoxFile, selsize, r, b, bbox=False, k=5, memory=False): n = r * b # number of hash functions - tC0 = time.clock() + tC0 = time.perf_counter() C = loadCoverage(wBoxFile) - tC1 = time.clock() + tC1 = time.perf_counter() maxCov = reduce(lambda x, y: x | y, C.values()) hashes = [lsh.hashFamily(i) for i in range(n)] @@ -234,27 +234,27 @@ def fast_(input_file, wBoxFile, selsize, r, b, bbox=False, k=5, memory=False): 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()) @@ -325,7 +325,7 @@ def fast_(input_file, wBoxFile, selsize, r, b, bbox=False, k=5, memory=False): del tcs_minhashes[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, tC1-tC0, ptime, prioritized_tcs[1:max_ts_size] @@ -469,28 +469,28 @@ def reductionPlusPlus(TS, C, S): # Returns: preparation time, reduction time, reduced test suite def fastPlusPlus(inputFile, wBoxFile, dim=0, S=1, 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: pTime, TS = pickle.load(open(rpFile, "rb")) - tC0 = time.clock() + tC0 = time.perf_counter() C = loadCoverage(wBoxFile) - tC1 = time.clock() + tC1 = time.perf_counter() - t2 = time.clock() + t2 = time.perf_counter() reducedTS = reductionPlusPlus(TS, C, S) - t3 = time.clock() + t3 = time.perf_counter() return pTime, tC1-tC0, t3-t2, reducedTS @@ -574,28 +574,28 @@ def reductionCS(TS, C, simple=True): # Returns: preparation time, reduction time, reduced test suite def fastCS(inputFile, wBoxFile, dim=0, memory=True, simple=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: pTime, TS = pickle.load(open(rpFile, "rb")) - tC0 = time.clock() + tC0 = time.perf_counter() C = loadCoverage(wBoxFile) - tC1 = time.clock() + tC1 = time.perf_counter() - t2 = time.clock() + t2 = time.perf_counter() reducedTS = reductionCS(TS, C, simple) - t3 = time.clock() + t3 = time.perf_counter() sTime = t3-t2 return pTime, tC1-tC0, sTime, reducedTS