Blob Blame History Raw
From f68dcdb47bfe6e069f4f6be10e6a47c55c2b9533 Mon Sep 17 00:00:00 2001
From: Sergio Pascual <sergiopr@fis.ucm.es>
Date: Thu, 11 Jul 2019 18:17:05 +0200
Subject: [PATCH] Replace deprecated time.clock with time.perf_counter

---
 bench/bsddb-table-bench.py   |  8 ++++----
 bench/recarray2-test.py      | 24 ++++++++++++------------
 bench/search-bench.py        | 16 ++++++++--------
 bench/searchsorted-bench.py  |  8 ++++----
 bench/searchsorted-bench2.py |  8 ++++----
 bench/shelve-bench.py        |  8 ++++----
 bench/sqlite-search-bench.py | 16 ++++++++--------
 bench/stress-test.py         |  8 ++++----
 bench/stress-test2.py        |  8 ++++----
 bench/stress-test3.py        |  8 ++++----
 bench/table-bench.py         |  8 ++++----
 tables/index.py              | 10 +++++-----
 12 files changed, 65 insertions(+), 65 deletions(-)

diff --git a/bench/bsddb-table-bench.py b/bench/bsddb-table-bench.py
index 49c4f809e..dd9f875b3 100644
--- a/bench/bsddb-table-bench.py
+++ b/bench/bsddb-table-bench.py
@@ -239,16 +239,16 @@ def readFile(filename, recsize, verbose):
     # Catch the hdf5 file passed as the last argument
     file = pargs[0]
 
-    t1 = time.clock()
+    t1 = time.perf_counter()
     psyco.bind(createFile)
     (rowsw, rowsz) = createFile(file, iterations, recsize, verbose)
-    t2 = time.clock()
+    t2 = time.perf_counter()
     tapprows = round(t2 - t1, 3)
 
-    t1 = time.clock()
+    t1 = time.perf_counter()
     psyco.bind(readFile)
     readFile(file, recsize, verbose)
-    t2 = time.clock()
+    t2 = time.perf_counter()
     treadrows = round(t2 - t1, 3)
 
     print("Rows written:", rowsw, " Row size:", rowsz)
diff --git a/bench/recarray2-test.py b/bench/recarray2-test.py
index e4affe213..a8602d80d 100644
--- a/bench/recarray2-test.py
+++ b/bench/recarray2-test.py
@@ -30,11 +30,11 @@
 
 print("Assignment in recarray original")
 print("-------------------------------")
-t1 = time.clock()
+t1 = time.perf_counter()
 for row in range(reclen):
     #r1.field("b")[row] = "changed"
     r1.field("c")[row] = float(row ** 2)
-t2 = time.clock()
+t2 = time.perf_counter()
 origtime = round(t2 - t1, 3)
 print("Assign time:", origtime, " Rows/s:", int(reclen / (origtime + delta)))
 # print "Field b on row 2 after re-assign:", r1.field("c")[2]
@@ -42,12 +42,12 @@
 
 print("Assignment in recarray modified")
 print("-------------------------------")
-t1 = time.clock()
+t1 = time.perf_counter()
 for row in range(reclen):
     rec = r2._row(row)  # select the row to be changed
     # rec.b = "changed"      # change the "b" field
     rec.c = float(row ** 2)  # Change the "c" field
-t2 = time.clock()
+t2 = time.perf_counter()
 ttime = round(t2 - t1, 3)
 print("Assign time:", ttime, " Rows/s:", int(reclen / (ttime + delta)),
       end=' ')
@@ -57,24 +57,24 @@
 
 print("Selection in recarray original")
 print("------------------------------")
-t1 = time.clock()
+t1 = time.perf_counter()
 for row in range(reclen):
     rec = r1[row]
     if rec.field("a") < 3:
         print("This record pass the cut ==>", rec.field("c"), "(row", row, ")")
-t2 = time.clock()
+t2 = time.perf_counter()
 origtime = round(t2 - t1, 3)
 print("Select time:", origtime, " Rows/s:", int(reclen / (origtime + delta)))
 print()
 
 print("Selection in recarray modified")
 print("------------------------------")
-t1 = time.clock()
+t1 = time.perf_counter()
 for row in range(reclen):
     rec = r2._row(row)
     if rec.a < 3:
         print("This record pass the cut ==>", rec.c, "(row", row, ")")
-t2 = time.clock()
+t2 = time.perf_counter()
 ttime = round(t2 - t1, 3)
 print("Select time:", ttime, " Rows/s:", int(reclen / (ttime + delta)),
       end=' ')
@@ -84,9 +84,9 @@
 print("Printing in recarray original")
 print("------------------------------")
 f = open("test.out", "w")
-t1 = time.clock()
+t1 = time.perf_counter()
 f.write(str(r1))
-t2 = time.clock()
+t2 = time.perf_counter()
 origtime = round(t2 - t1, 3)
 f.close()
 os.unlink("test.out")
@@ -95,9 +95,9 @@
 print("Printing in recarray modified")
 print("------------------------------")
 f = open("test2.out", "w")
-t1 = time.clock()
+t1 = time.perf_counter()
 f.write(str(r2))
-t2 = time.clock()
+t2 = time.perf_counter()
 ttime = round(t2 - t1, 3)
 f.close()
 os.unlink("test2.out")
diff --git a/bench/search-bench.py b/bench/search-bench.py
index a56f738a8..11d88349f 100644
--- a/bench/search-bench.py
+++ b/bench/search-bench.py
@@ -92,7 +92,7 @@ def createFile(filename, nrows, filters, index, heavy, noise, verbose):
                                None, nrows)
 
     t1 = time.time()
-    cpu1 = time.clock()
+    cpu1 = time.perf_counter()
     nrowsbuf = table.nrowsinbuf
     minimum = 0
     maximum = nrows
@@ -115,7 +115,7 @@ def createFile(filename, nrows, filters, index, heavy, noise, verbose):
     table.flush()
     rowswritten += nrows
     time1 = time.time() - t1
-    tcpu1 = time.clock() - cpu1
+    tcpu1 = time.perf_counter() - cpu1
     print("Time for filling:", round(time1, 3),
           "Krows/s:", round(nrows / 1000. / time1, 3), end=' ')
     fileh.close()
@@ -127,14 +127,14 @@ def createFile(filename, nrows, filters, index, heavy, noise, verbose):
     rowsize = table.rowsize
     if index:
         t1 = time.time()
-        cpu1 = time.clock()
+        cpu1 = time.perf_counter()
         # Index all entries
         if not heavy:
             indexrows = table.cols.var1.create_index(filters=filters)
         for colname in ['var2', 'var3']:
             table.colinstances[colname].create_index(filters=filters)
         time2 = time.time() - t1
-        tcpu2 = time.clock() - cpu1
+        tcpu2 = time.perf_counter() - cpu1
         print("Time for indexing:", round(time2, 3),
               "iKrows/s:", round(indexrows / 1000. / time2, 3), end=' ')
     else:
@@ -250,7 +250,7 @@ def readFile(filename, atom, riter, indexmode, dselect, verbose):
         # The interval for look values at. This is aproximately equivalent to
         # the number of elements to select
         rnd = numpy.random.randint(table.nrows)
-        cpu1 = time.clock()
+        cpu1 = time.perf_counter()
         t1 = time.time()
         if atom == "string":
             val = str(rnd)[-4:]
@@ -284,17 +284,17 @@ def readFile(filename, atom, riter, indexmode, dselect, verbose):
         if i == 0:
             # First iteration
             time1 = time.time() - t1
-            tcpu1 = time.clock() - cpu1
+            tcpu1 = time.perf_counter() - cpu1
         else:
             if indexmode == "indexed":
                 # if indexed, wait until the 5th iteration (in order to
                 # insure that the index is effectively cached) to take times
                 if i >= 5:
                     time2 += time.time() - t1
-                    tcpu2 += time.clock() - cpu1
+                    tcpu2 += time.perf_counter() - cpu1
             else:
                 time2 += time.time() - t1
-                tcpu2 += time.clock() - cpu1
+                tcpu2 += time.perf_counter() - cpu1
 
     if riter > 1:
         if indexmode == "indexed" and riter >= 5:
diff --git a/bench/searchsorted-bench.py b/bench/searchsorted-bench.py
index f595de51e..a4bfe7d3b 100644
--- a/bench/searchsorted-bench.py
+++ b/bench/searchsorted-bench.py
@@ -295,13 +295,13 @@ def searchFile(filename, atom, verbose, item):
             if shuffle:
                 print("Suffling...")
         t1 = time.time()
-        cpu1 = time.clock()
+        cpu1 = time.perf_counter()
         if psyco_imported and usepsyco:
             psyco.bind(createFile)
         (rowsw, rowsz) = createFile(file, nrows, filters,
                                     atom, recsize, index, verbose)
         t2 = time.time()
-        cpu2 = time.clock()
+        cpu2 = time.perf_counter()
         tapprows = round(t2 - t1, 3)
         cpuapprows = round(cpu2 - cpu1, 3)
         tpercent = int(round(cpuapprows / tapprows, 2) * 100)
@@ -316,14 +316,14 @@ def searchFile(filename, atom, verbose, item):
             psyco.bind(readFile)
             psyco.bind(searchFile)
         t1 = time.time()
-        cpu1 = time.clock()
+        cpu1 = time.perf_counter()
         if rng or item:
             (rowsr, uncomprB, niter) = searchFile(file, atom, verbose, item)
         else:
             for i in range(1):
                 (rowsr, rowsel, rowsz) = readFile(file, atom, niter, verbose)
         t2 = time.time()
-        cpu2 = time.clock()
+        cpu2 = time.perf_counter()
         treadrows = round(t2 - t1, 3)
         cpureadrows = round(cpu2 - cpu1, 3)
         tpercent = int(round(cpureadrows / treadrows, 2) * 100)
diff --git a/bench/searchsorted-bench2.py b/bench/searchsorted-bench2.py
index f8446aed4..2b88e11d6 100644
--- a/bench/searchsorted-bench2.py
+++ b/bench/searchsorted-bench2.py
@@ -295,13 +295,13 @@ def searchFile(filename, atom, verbose, item):
             if shuffle:
                 print("Suffling...")
         t1 = time.time()
-        cpu1 = time.clock()
+        cpu1 = time.perf_counter()
         if psyco_imported and usepsyco:
             psyco.bind(createFile)
         (rowsw, rowsz) = createFile(file, nrows, filters,
                                     atom, recsize, index, verbose)
         t2 = time.time()
-        cpu2 = time.clock()
+        cpu2 = time.perf_counter()
         tapprows = round(t2 - t1, 3)
         cpuapprows = round(cpu2 - cpu1, 3)
         tpercent = int(round(cpuapprows / tapprows, 2) * 100)
@@ -316,14 +316,14 @@ def searchFile(filename, atom, verbose, item):
             psyco.bind(readFile)
             psyco.bind(searchFile)
         t1 = time.time()
-        cpu1 = time.clock()
+        cpu1 = time.perf_counter()
         if rng or item:
             (rowsr, uncomprB, niter) = searchFile(file, atom, verbose, item)
         else:
             for i in range(1):
                 (rowsr, rowsel, rowsz) = readFile(file, atom, niter, verbose)
         t2 = time.time()
-        cpu2 = time.clock()
+        cpu2 = time.perf_counter()
         treadrows = round(t2 - t1, 3)
         cpureadrows = round(cpu2 - cpu1, 3)
         tpercent = int(round(cpureadrows / treadrows, 2) * 100)
diff --git a/bench/shelve-bench.py b/bench/shelve-bench.py
index 4a891c02d..d30739d83 100644
--- a/bench/shelve-bench.py
+++ b/bench/shelve-bench.py
@@ -178,16 +178,16 @@ def readFile(filename, recsize):
     # Catch the hdf5 file passed as the last argument
     file = pargs[0]
 
-    t1 = time.clock()
+    t1 = time.perf_counter()
     psyco.bind(createFile)
     (rowsw, rowsz) = createFile(file, iterations, recsize)
-    t2 = time.clock()
+    t2 = time.perf_counter()
     tapprows = round(t2 - t1, 3)
 
-    t1 = time.clock()
+    t1 = time.perf_counter()
     psyco.bind(readFile)
     readFile(file, recsize)
-    t2 = time.clock()
+    t2 = time.perf_counter()
     treadrows = round(t2 - t1, 3)
 
     print("Rows written:", rowsw, " Row size:", rowsz)
diff --git a/bench/sqlite-search-bench.py b/bench/sqlite-search-bench.py
index 995fe0e36..76dc7c57e 100644
--- a/bench/sqlite-search-bench.py
+++ b/bench/sqlite-search-bench.py
@@ -123,7 +123,7 @@ def createFile(filename, nrows, filters, indexmode, heavy, noise, bfile,
         # Insert rows
         SQL = "insert into small values(NULL, %s)" % place_holders
         time1 = time.time()
-        cpu1 = time.clock()
+        cpu1 = time.perf_counter()
         # This way of filling is to copy the PyTables benchmark
         nrowsbuf = 1000
         minimum = 0
@@ -149,7 +149,7 @@ def createFile(filename, nrows, filters, indexmode, heavy, noise, bfile,
                 cursor.execute(SQL, fields)
             conn.commit()
         t1 = round(time.time() - time1, 5)
-        tcpu1 = round(time.clock() - cpu1, 5)
+        tcpu1 = round(time.perf_counter() - cpu1, 5)
         rowsecf = nrows / t1
         size1 = os.stat(dbfile)[6]
         print("******** Results for writing nrows = %s" % (nrows), "*********")
@@ -160,7 +160,7 @@ def createFile(filename, nrows, filters, indexmode, heavy, noise, bfile,
     # Indexem
     if indexmode == "indexed":
         time1 = time.time()
-        cpu1 = time.clock()
+        cpu1 = time.perf_counter()
         if not heavy:
             cursor.execute("CREATE INDEX ivar1 ON small(var1)")
             conn.commit()
@@ -169,7 +169,7 @@ def createFile(filename, nrows, filters, indexmode, heavy, noise, bfile,
         cursor.execute("CREATE INDEX ivar3 ON small(var3)")
         conn.commit()
         t2 = round(time.time() - time1, 5)
-        tcpu2 = round(time.clock() - cpu1, 5)
+        tcpu2 = round(time.perf_counter() - cpu1, 5)
         rowseci = nrows / t2
         print(("Index time:", t2, ", IKRows/s:",
               round((nrows / 10. ** 3) / t2, 3),))
@@ -284,7 +284,7 @@ def readFile(dbfile, nrows, indexmode, heavy, dselect, bfile, riter):
         for i in range(riter):
             rnd = random.randrange(nrows)
             time1 = time.time()
-            cpu1 = time.clock()
+            cpu1 = time.perf_counter()
             if atom == "string":
                 #cursor.execute(SQL1, "1111")
                 cursor.execute(SQL1, str(rnd)[-4:])
@@ -299,7 +299,7 @@ def readFile(dbfile, nrows, indexmode, heavy, dselect, bfile, riter):
                     "atom must take a value in ['string','int','float']")
             if i == 0:
                 t1 = time.time() - time1
-                tcpu1 = time.clock() - cpu1
+                tcpu1 = time.perf_counter() - cpu1
             else:
                 if indexmode == "indexed":
                     # if indexed, wait until the 5th iteration to take
@@ -307,10 +307,10 @@ def readFile(dbfile, nrows, indexmode, heavy, dselect, bfile, riter):
                     # effectively cached)
                     if i >= 5:
                         time2 += time.time() - time1
-                        cpu2 += time.clock() - cpu1
+                        cpu2 += time.perf_counter() - cpu1
                 else:
                     time2 += time.time() - time1
-                    time2 += time.clock() - cpu1
+                    time2 += time.perf_counter() - cpu1
         if riter > 1:
             if indexmode == "indexed" and riter >= 5:
                 correction = 5
diff --git a/bench/stress-test.py b/bench/stress-test.py
index 109e7a433..3eb6c9ca0 100644
--- a/bench/stress-test.py
+++ b/bench/stress-test.py
@@ -265,14 +265,14 @@ def testMethod(file, usearray, testwrite, testread, complib, complevel,
         print("Compression library:", complib)
     if testwrite:
         t1 = time.time()
-        cpu1 = time.clock()
+        cpu1 = time.perf_counter()
         if usearray:
             (rowsw, rowsz) = createFileArr(file, ngroups, ntables, nrows)
         else:
             (rowsw, rowsz) = createFile(file, ngroups, ntables, nrows,
                                         complevel, complib, recsize)
         t2 = time.time()
-        cpu2 = time.clock()
+        cpu2 = time.perf_counter()
         tapprows = round(t2 - t1, 3)
         cpuapprows = round(cpu2 - cpu1, 3)
         tpercent = int(round(cpuapprows / tapprows, 2) * 100)
@@ -284,14 +284,14 @@ def testMethod(file, usearray, testwrite, testread, complib, complevel,
 
     if testread:
         t1 = time.time()
-        cpu1 = time.clock()
+        cpu1 = time.perf_counter()
         if usearray:
             (rowsr, rowsz, bufsz) = readFileArr(file,
                                                 ngroups, recsize, verbose)
         else:
             (rowsr, rowsz, bufsz) = readFile(file, ngroups, recsize, verbose)
         t2 = time.time()
-        cpu2 = time.clock()
+        cpu2 = time.perf_counter()
         treadrows = round(t2 - t1, 3)
         cpureadrows = round(cpu2 - cpu1, 3)
         tpercent = int(round(cpureadrows / treadrows, 2) * 100)
diff --git a/bench/stress-test2.py b/bench/stress-test2.py
index 1dc91fe8d..9a2868284 100644
--- a/bench/stress-test2.py
+++ b/bench/stress-test2.py
@@ -200,13 +200,13 @@ def dump_garbage():
         print("Compression library:", complib)
     if testwrite:
         t1 = time.time()
-        cpu1 = time.clock()
+        cpu1 = time.perf_counter()
         if psyco_imported and usepsyco:
             psyco.bind(createFile)
         (rowsw, rowsz) = createFile(file, ngroups, ntables, nrows,
                                     complevel, complib, recsize)
         t2 = time.time()
-        cpu2 = time.clock()
+        cpu2 = time.perf_counter()
         tapprows = round(t2 - t1, 3)
         cpuapprows = round(cpu2 - cpu1, 3)
         tpercent = int(round(cpuapprows / tapprows, 2) * 100)
@@ -218,12 +218,12 @@ def dump_garbage():
 
     if testread:
         t1 = time.time()
-        cpu1 = time.clock()
+        cpu1 = time.perf_counter()
         if psyco_imported and usepsyco:
             psyco.bind(readFile)
         (rowsr, rowsz, bufsz) = readFile(file, ngroups, recsize, verbose)
         t2 = time.time()
-        cpu2 = time.clock()
+        cpu2 = time.perf_counter()
         treadrows = round(t2 - t1, 3)
         cpureadrows = round(cpu2 - cpu1, 3)
         tpercent = int(round(cpureadrows / treadrows, 2) * 100)
diff --git a/bench/stress-test3.py b/bench/stress-test3.py
index 42630f597..bed9ec976 100644
--- a/bench/stress-test3.py
+++ b/bench/stress-test3.py
@@ -245,7 +245,7 @@ def dump_garbage():
         print("Compression library:", complib)
     if testwrite:
         t1 = time.time()
-        cpu1 = time.clock()
+        cpu1 = time.perf_counter()
         if psyco_imported and usepsyco:
             psyco.bind(createFile)
         if usearray:
@@ -254,7 +254,7 @@ def dump_garbage():
             (rowsw, rowsz) = createFile(file, ngroups, ntables, nrows,
                                         complevel, complib, recsize)
         t2 = time.time()
-        cpu2 = time.clock()
+        cpu2 = time.perf_counter()
         tapprows = round(t2 - t1, 3)
         cpuapprows = round(cpu2 - cpu1, 3)
         tpercent = int(round(cpuapprows / tapprows, 2) * 100)
@@ -266,7 +266,7 @@ def dump_garbage():
 
     if testread:
         t1 = time.time()
-        cpu1 = time.clock()
+        cpu1 = time.perf_counter()
         if psyco_imported and usepsyco:
             psyco.bind(readFile)
         if usearray:
@@ -275,7 +275,7 @@ def dump_garbage():
         else:
             (rowsr, rowsz, bufsz) = readFile(file, ngroups, recsize, verbose)
         t2 = time.time()
-        cpu2 = time.clock()
+        cpu2 = time.perf_counter()
         treadrows = round(t2 - t1, 3)
         cpureadrows = round(cpu2 - cpu1, 3)
         tpercent = int(round(cpureadrows / treadrows, 2) * 100)
diff --git a/bench/table-bench.py b/bench/table-bench.py
index 64d304ba9..e9e176559 100644
--- a/bench/table-bench.py
+++ b/bench/table-bench.py
@@ -372,7 +372,7 @@ def readField(filename, field, rng, verbose):
             if shuffle:
                 print("Suffling...")
         t1 = time.time()
-        cpu1 = time.clock()
+        cpu1 = time.perf_counter()
         if psyco_imported and usepsyco:
             psyco.bind(createFile)
         if profile:
@@ -389,7 +389,7 @@ def readField(filename, field, rng, verbose):
         else:
             (rowsw, rowsz) = createFile(file, iterations, filters, recsize)
         t2 = time.time()
-        cpu2 = time.clock()
+        cpu2 = time.perf_counter()
         tapprows = round(t2 - t1, 3)
         cpuapprows = round(cpu2 - cpu1, 3)
         tpercent = int(round(cpuapprows / tapprows, 2) * 100)
@@ -401,7 +401,7 @@ def readField(filename, field, rng, verbose):
 
     if testread:
         t1 = time.time()
-        cpu1 = time.clock()
+        cpu1 = time.perf_counter()
         if psyco_imported and usepsyco:
             psyco.bind(readFile)
             # psyco.bind(readField)
@@ -413,7 +413,7 @@ def readField(filename, field, rng, verbose):
             for i in range(1):
                 (rowsr, rowsz) = readFile(file, recsize, verbose)
         t2 = time.time()
-        cpu2 = time.clock()
+        cpu2 = time.perf_counter()
         treadrows = round(t2 - t1, 3)
         cpureadrows = round(cpu2 - cpu1, 3)
         tpercent = int(round(cpureadrows / treadrows, 2) * 100)
diff --git a/tables/index.py b/tables/index.py
index e5b3f8321..25300e4c0 100644
--- a/tables/index.py
+++ b/tables/index.py
@@ -23,7 +23,7 @@
 import tempfile
 import warnings
 
-from time import time, clock
+from time import time, perf_counter
 
 import numpy
 
@@ -847,7 +847,7 @@ def do_complete_sort(self):
 
         if self.verbose:
             t1 = time()
-            c1 = clock()
+            c1 = perf_counter()
         ss = self.slicesize
         tmp = self.tmp
         ranges = tmp.ranges[:]
@@ -953,7 +953,7 @@ def do_complete_sort(self):
         self.compute_overlaps(self.tmp, "do_complete_sort()", self.verbose)
         if self.verbose:
             t = round(time() - t1, 4)
-            c = round(clock() - c1, 4)
+            c = round(perf_counter() - c1, 4)
             print("time: %s. clock: %s" % (t, c))
 
     def swap(self, what, mode=None):
@@ -968,7 +968,7 @@ def swap(self, what, mode=None):
 
         if self.verbose:
             t1 = time()
-            c1 = clock()
+            c1 = perf_counter()
         if what == "chunks":
             self.swap_chunks(mode)
         elif what == "slices":
@@ -982,7 +982,7 @@ def swap(self, what, mode=None):
         rmult = len(mult.nonzero()[0]) / float(len(mult))
         if self.verbose:
             t = round(time() - t1, 4)
-            c = round(clock() - c1, 4)
+            c = round(perf_counter() - c1, 4)
             print("time: %s. clock: %s" % (t, c))
         # Check that entropy is actually decreasing
         if what == "chunks" and self.last_tover > 0. and self.last_nover > 0: