mirror of
https://github.com/wassname/simpeg.git
synced 2026-07-13 17:45:30 +08:00
test counter utils
This commit is contained in:
@@ -26,6 +26,26 @@ class TestCheckDerivative(unittest.TestCase):
|
||||
self.assertTrue(not passed, True)
|
||||
|
||||
|
||||
class TestCounter(unittest.TestCase):
|
||||
def test_simpleFail(self):
|
||||
class MyClass(object):
|
||||
def __init__(self, url):
|
||||
self.counter = Counter()
|
||||
|
||||
@count
|
||||
def MyMethod(self):
|
||||
pass
|
||||
|
||||
@timeIt
|
||||
def MySecondMethod(self):
|
||||
pass
|
||||
|
||||
c = MyClass('blah')
|
||||
for i in range(100): c.MyMethod()
|
||||
for i in range(300): c.MySecondMethod()
|
||||
c.counter.summary()
|
||||
self.assertTrue(True)
|
||||
|
||||
class TestSequenceFunctions(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
||||
@@ -93,22 +93,3 @@ def timeIt(f):
|
||||
if type(counter) is Counter: counter.countToc(self.__class__.__name__+'.'+f.__name__)
|
||||
return out
|
||||
return wrapper
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
class MyClass(object):
|
||||
def __init__(self, url):
|
||||
self.counter = Counter()
|
||||
|
||||
@count
|
||||
def MyMethod(self):
|
||||
pass
|
||||
|
||||
@timeIt
|
||||
def MySecondMethod(self):
|
||||
pass
|
||||
|
||||
c = MyClass('blah')
|
||||
for i in range(100): c.MyMethod()
|
||||
for i in range(300): c.MySecondMethod()
|
||||
c.counter.summary()
|
||||
|
||||
@@ -51,3 +51,39 @@ Interpolation Utilities
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
Counter Utilities
|
||||
=======================
|
||||
|
||||
::
|
||||
class MyClass(object):
|
||||
def __init__(self, url):
|
||||
self.counter = Counter()
|
||||
|
||||
@count
|
||||
def MyMethod(self):
|
||||
pass
|
||||
|
||||
@timeIt
|
||||
def MySecondMethod(self):
|
||||
pass
|
||||
|
||||
c = MyClass('blah')
|
||||
for i in range(100): c.MyMethod()
|
||||
for i in range(300): c.MySecondMethod()
|
||||
c.counter.summary()
|
||||
|
||||
::
|
||||
|
||||
Counters:
|
||||
MyClass.MyMethod : 100
|
||||
|
||||
Times: mean sum
|
||||
MyClass.MySecondMethod : 1.70e-06, 5.10e-04, 300x
|
||||
|
||||
The API
|
||||
-------
|
||||
|
||||
.. automodule:: SimPEG.Utils.CounterUtils
|
||||
:members:
|
||||
:undoc-members:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user