Skip to content

Commit

Permalink
Switch time.clock() -> time.perf_counter()
Browse files Browse the repository at this point in the history
  • Loading branch information
rmcgibbo authored and tkralphs committed Feb 9, 2021
1 parent a2da4b5 commit 909253a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
6 changes: 3 additions & 3 deletions cylp/cy/CyTest.pyx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import print_function
import sys
from time import clock
from time import perf_counter
from cylp.cy.CyClpSimplex cimport CyClpSimplex
from cylp.cy.CyDantzigPivot cimport CyDantzigPivot
from cylp.cy.CyPEPivot cimport CyPEPivot
Expand All @@ -21,7 +21,7 @@ def CySolve(fileName, method):
ppivot = CyPEPivot(s)
s.setPrimalColumnPivotAlgorithm(ppivot.CppSelf)

start = clock()
start = perf_counter()
s.primal()
print('Exec time: ', clock() - start)
print('Exec time: ', perf_counter() - start)
return s.objectiveValue
6 changes: 3 additions & 3 deletions cylp/py/PySolve.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import print_function
import sys
from time import clock
from time import perf_counter
import cProfile
import numpy as np
from cylp.cy import CyClpSimplex
Expand Down Expand Up @@ -35,9 +35,9 @@ def solve(filename, method):

#s.setPerturbation(50)

start = clock()
start = perf_counter()
s.primal()
print('Problem solved in %g seconds.' % (clock() - start))
print('Problem solved in %g seconds.' % (perf_counter() - start))
return s.objectiveValue


Expand Down
38 changes: 19 additions & 19 deletions cylp/py/QP/QP.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import sys
import cProfile
import inspect
from time import clock
from time import perf_counter
import numpy as np
from scipy import sparse
from cylp.cy import CyClpSimplex
Expand Down Expand Up @@ -326,7 +326,7 @@ def convertToEqualityOnly(self, varsToo=True):

def WolfeEquality(self, method='w'):
assert(self.nInEquality == 0)
start = clock()
start = perf_counter()
A = self.A
b = CyLPArray(self.b)
c = CyLPArray(self.c)
Expand Down Expand Up @@ -415,10 +415,10 @@ def WolfeEquality(self, method='w'):
#print('comp list:\n', p.complementarityList)

s.setPivotMethod(p)
timeToMake = clock() - start
start = clock()
timeToMake = perf_counter() - start
start = perf_counter()
s.primal()
timeToSolve = clock() - start
timeToSolve = perf_counter() - start

self.writeReport('qpout', s, timeToMake, timeToSolve, method, p)

Expand Down Expand Up @@ -487,13 +487,13 @@ def WolfeEquality(self, method='w'):
# #print('comp list:\n', p.complementarityList)
#
# s.setPivotMethod(p)
## timeToMake = clock() - start
## start = clock()
## timeToMake = perf_counter() - start
## start = perf_counter()
# s.primal()



# timeToSolve = clock() - start
# timeToSolve = perf_counter() - start
#s.initialPrimalSolve()
if method == 'wp':
total = p.compCount + p.nonCompCount
Expand Down Expand Up @@ -872,9 +872,9 @@ def Wolfe_2(self):
p = PositiveEdgeWolfePivot(s, bucketSize=float(sys.argv[2]))
s.setPivotMethod(p)

st = clock()
st = perf_counter()
s.primal()
print("CLP time : %g seconds" % (clock() - st))
print("CLP time : %g seconds" % (perf_counter() - st))

x = s.getPrimalVariableSolution()
print("sol = ")
Expand All @@ -894,7 +894,7 @@ def Wolfe(self, method='w'):
Solves a QP using Wolfe's method (``method = 'w'``) or Wolfe's method using
positive edge as pivot rule (``method = 'wp'``).
'''
start = clock()
start = perf_counter()
A = self.A
G = self.G
b = CyLPArray(self.b)
Expand Down Expand Up @@ -1243,10 +1243,10 @@ def Wolfe(self, method='w'):

#print(p.complementarityList)
s.setPivotMethod(p)
timeToMake = clock() - start
start = clock()
timeToMake = perf_counter() - start
start = perf_counter()
s.primal()
timeToSolve = clock() - start
timeToSolve = perf_counter() - start
#s.initialPrimalSolve()
if method == 'wp':
total = p.compCount + p.nonCompCount
Expand Down Expand Up @@ -1598,9 +1598,9 @@ def Wolfe(self, method='w'):
#p = PositiveEdgeWolfePivot(s, bucketSize=float(sys.argv[2]))
s.setPivotMethod(p)

st = clock()
st = perf_counter()
s.primal()
print("CLP time : %g seconds" % (clock() - st))
print("CLP time : %g seconds" % (perf_counter() - st))

x = s.getPrimalVariableSolution()
print("sol = ")
Expand Down Expand Up @@ -1651,21 +1651,21 @@ def getStat():

def QPTest():
qp = QP()
start = clock()
start = perf_counter()
qp.fromQps(sys.argv[1])
qp.convertToEqualityOnly()
if len(sys.argv) > 2:
qp.WolfeEquality(sys.argv[2])
else:
qp.WolfeEquality()
return
r = clock() - start
r = perf_counter() - start
if len(sys.argv) > 2:
qp.Wolfe(sys.argv[2])
else:
qp.Wolfe()
print('took %g seconds to read the problem' % r)
print('took %g seconds to solve the problem' % (clock() - start))
print('took %g seconds to solve the problem' % (perf_counter() - start))
print("done")

import sys
Expand Down

0 comments on commit 909253a

Please sign in to comment.