Example #1
0
def run(monitors, loops, record_type=None):
    """ Time the monitors overhead using pystones.

    Parameter
    ---------
    monitors : list
        The list of monitors to time.

    loops : int
        The number of loops to run pystones.

    record_type : object
        The type of record to use.

    """
    header = (
        "Overhead time | Relative overhead | "
        "{:^10} | {:^{length}}".format(
            'Records', 'Name',
            length=max(len(key) for key in monitors) - 4))
    line = ('{time:>13} | {relative:>17} | {records:>10} | {name}')
    print header
    print len(header) * '-'
    expected_time, _ = pystone.pystones(loops)
    for name, monitor in monitors.iteritems():
        recorder = RecordCounter()
        with monitor(recorder=recorder, record_type=record_type):
            time, _ = pystone.pystones(loops)
        print line.format(
            name=name,
            time='{:2.2f}'.format(time - expected_time),
            relative='{:.2%}'.format((time - expected_time) / expected_time),
            records='{:10d}'.format(recorder.records))
Example #2
0
    def Calibrate(self, duration = 2):
        startTime = blue.os.GetWallclockTimeNow()
        stepCount = 0
        while blue.os.GetWallclockTimeNow() - startTime < duration * 10000000:
            stepCount += 1
            pystones(self.pyStonesPerUnit)

        return int(stepCount * self.pyStonesPerUnit / duration)
Example #3
0
def determineT():
    def pystones(*args, **kwargs):
        from warnings import warn
        warn("Python module 'test.pystone' not available. Will assume T=1.0")
        return 1.0, "ignored"

    pystonesValueFile = expanduser('~/.seecr-test-pystones')
    if isfile(pystonesValueFile):
        age = time() - stat(pystonesValueFile).st_mtime
        if age < 12 * 60 * 60:
            return float(open(pystonesValueFile).read())

    temppath = []
    while len(path) > 0:
        try:
            if 'test' in sys.modules:
                del sys.modules['test']
            from test.pystone import pystones

            break
        except ImportError:
            temppath.append(path[0])
            del path[0]
    for temp in reversed(temppath):
        path.insert(0, temp)
    del temppath
    T, p = pystones(loops=50000)
    try:
        with open(pystonesValueFile, 'w') as f:
            f.write(str(T))
    except IOError:
        pass
    return T
Example #4
0
def determineT():
    def pystones(*args, **kwargs):
        from warnings import warn
        warn("Python module 'test.pystone' not available. Will assume T=1.0")
        return 1.0, "ignored"

    pystonesValueFile = expanduser('~/.seecr-test-pystones')
    if isfile(pystonesValueFile):
        age = time() - stat(pystonesValueFile).st_mtime
        if age < 12 * 60 * 60:
            with open(pystonesValueFile) as fp:
                return float(fp.read())

    temppath = []
    while len(path) > 0:
        try:
            if 'test' in sys.modules:
                del sys.modules['test']
            from test.pystone import pystones

            break
        except ImportError:
            temppath.append(path[0])
            del path[0]
    for temp in reversed(temppath):
        path.insert(0, temp)
    del temppath
    T, p = pystones(loops=50000)
    try:
        with open(pystonesValueFile, 'w') as f:
            f.write(str(T))
    except IOError:
        pass
    return T
Example #5
0
    def pystonesPerSecond(self):
        """How many pystones are equivalent to one second on this machine"""

        # deferred import as workaround for Zope 2 testrunner issue:
        # http://www.zope.org/Collectors/Zope/2268
        from test import pystone
        if self._pystones_per_second == None:
            self._pystones_per_second = pystone.pystones(pystone.LOOPS/10)[1]
        return self._pystones_per_second
Example #6
0
 def _duration(*args, **kwargs):
     time = 0
     try:
         time = Timer(lambda: function(*args, **kwargs)).timeit(repeat)
     finally:
         benchtime, pystones = pystone.pystones()
         kstones = (pystones * time) / 1000
         print '%s : time = %f kstones = %f' % (function.__name__, time, kstones)
     return function(*args, **kwargs)
Example #7
0
    def pystonesPerSecond(self):
        """How many pystones are equivalent to one second on this machine"""

        # deferred import as workaround for Zope 2 testrunner issue:
        # http://www.zope.org/Collectors/Zope/2268
        from test import pystone
        if self._pystones_per_second == None:
            self._pystones_per_second = pystone.pystones(pystone.LOOPS/10)[1]
        return self._pystones_per_second
Example #8
0
 def _duration(*args, **kwargs):
     time = 0
     try:
         time = Timer(lambda: function(*args, **kwargs)).timeit(repeat)
     finally:
         benchtime, pystones = pystone.pystones()
         kstones = (pystones * time) / 1000
         print '%s : time = %f kstones = %f' % (function.__name__, time, kstones)
     return function(*args, **kwargs)
    def testWorkflowActionAndGetState(self):

        foo_list = []
        foo_list_append = foo_list.append
        range_10 = range(10)
        portal_workflow = self.portal.portal_workflow
        foo_count = 100

        for x in xrange(foo_count):
            foo = self.foo_module.newContent()
            foo_list_append(foo)

        self.assertEqual('draft', foo_list[0].getSimulationState())

        start = time()
        for foo in foo_list:
            foo.getSimulationState()
            action_list = portal_workflow.listActions(object=foo)
            for x in range_10:
                try:
                    portal_workflow.doActionFor(foo, 'dummy_failing_action')
                except ValidationFailed:
                    pass
                portal_workflow.doActionFor(foo, 'dummy_action')
            portal_workflow.doActionFor(foo, 'validate_action')
            foo.getSimulationState()

        end = time()

        print "\n%s pystones/second" % pystone.pystones()[1]
        message = "\n%s took %.4gs (%s foo(s))" % (self._testMethodName,
                                                   end - start, foo_count)
        print message
        ZopeTestCase._print(message)

        # some checking to make sure we tested something relevant
        self.assertEqual('validated', foo.getSimulationState())
        expected_action_id_list = [
            'custom_action_no_dialog', 'custom_dialog_action',
            'custom_dialog_required_action', 'display_status_action',
            'dummy_action', 'dummy_crashing_action', 'dummy_failing_action',
            'validate_action'
        ]
        expected_action_id_list.sort()
        found_action_id_list = [
            x['id'] for x in action_list if x['category'] == 'workflow'
        ]
        found_action_id_list.sort()
        self.assertEqual(expected_action_id_list, found_action_id_list)
        self.assertEqual(
            23,
            len(foo.Base_getWorkflowHistoryItemList('foo_workflow',
                                                    display=0)))
Example #10
0
  def testWorkflowActionAndGetState(self):

    foo_list = []
    foo_list_append = foo_list.append
    range_10 = range(10)
    portal_workflow = self.portal.portal_workflow
    foo_count = 100

    for x in xrange(foo_count):
      foo = self.foo_module.newContent()
      foo_list_append(foo)

    self.assertEqual('draft', foo_list[0].getSimulationState())

    start = time()
    for foo in foo_list:
      foo.getSimulationState()
      action_list = portal_workflow.listActions(object=foo)
      for x in range_10:
        try:
          portal_workflow.doActionFor(foo, 'dummy_failing_action')
        except ValidationFailed:
          pass
        portal_workflow.doActionFor(foo, 'dummy_action')
      portal_workflow.doActionFor(foo, 'validate_action')
      foo.getSimulationState()

    end = time()

    print "\n%s pystones/second" % pystone.pystones()[1]
    message = "\n%s took %.4gs (%s foo(s))" % (self._testMethodName,
                                             end - start, foo_count)
    print message
    ZopeTestCase._print(message)

    # some checking to make sure we tested something relevant
    self.assertEqual('validated', foo.getSimulationState())
    expected_action_id_list = ['custom_action_no_dialog', 'custom_dialog_action',
                               'display_status_action', 'dummy_action',
                               'dummy_failing_action', 'validate_action']
    expected_action_id_list.sort()
    found_action_id_list = [x['id'] for x in action_list if x['category'] == 'workflow']
    found_action_id_list.sort()
    self.assertEqual(expected_action_id_list, found_action_id_list)
    self.assertEqual(23, len(foo.Base_getWorkflowHistoryItemList('foo_workflow', display=0)))
Example #11
0
def getpystone():
    # Iteratively find the pystone performance of the CPU

    # Prefers using Python's standard pystones library, otherwise SABnzbd's pystones library
    try:
        # Try to import from the python standard library
        from test.pystone import pystones
    except:
        try:
            # fallback: try to import from SABnzbd's library
            from pystone import pystones
        except:
            return None   # no pystone library found

    # if we arrive here, we were able to succesfully import pystone, so start calculation
    maxpystone = None
    # Start with a short run, find the the pystone, and increase runtime until duration took > 0.1 second
    for pyseed in [1000, 2000, 5000, 10000, 20000, 50000, 100000, 200000]:
        duration, pystonefloat = pystones(pyseed)
        maxpystone = max(maxpystone, int(pystonefloat))
        # Stop when pystone() has been running for at least 0.1 second
        if duration > 0.1:
            break
    return maxpystone
Example #12
0
def getpystone():
    # Iteratively find the pystone performance of the CPU

    # Prefers using Python's standard pystones library, otherwise SABnzbd's pystones library
    try:
        # Try to import from the python standard library
        from test.pystone import pystones
    except:
        try:
            # fallback: try to import from SABnzbd's library
            from pystone import pystones
        except:
            return None  # no pystone library found

    # if we arrive here, we were able to succesfully import pystone, so start calculation
    maxpystone = None
    # Start with a short run, find the the pystone, and increase runtime until duration took > 0.1 second
    for pyseed in [1000, 2000, 5000, 10000, 20000, 50000, 100000, 200000]:
        duration, pystonefloat = pystones(pyseed)
        maxpystone = max(maxpystone, int(pystonefloat))
        # Stop when pystone() has been running for at least 0.1 second
        if duration > 0.1:
            break
    return maxpystone
Example #13
0
 def perf_00_setupAndFillCache(self):
   self.test_01_OrderWithSimpleTaxedAndDiscountedLines()
   self.__class__._order = self['order'].getRelativeUrl()
   self.runAlarms()
   print "\n%s pystones/second" % pystone.pystones()[1]
Example #14
0
 def test_pystone(self):
     print "PYSTONE RESULT (time,score) : %r" % (pystone.pystones(), )
Example #15
0
from test import pystone


def seconds_to_pystones(seconds):
    benchtime, pystones = pystone.pystones()
    return (pystones * seconds) / 1000


print pystone.pystones()
benchtime, pystones = pystone.pystones()
print benchtime, pystones
print seconds_to_pystones(3)
Example #16
0
 def __init__(self, function):
     from test import pystone
     self.function = function
     if not hasattr(Pystone_Test, "pystones_per_second"):
         Pystone_Test.pystones_per_second = pystone.pystones(pystone.LOOPS)
def benchmark():
    return pystone.pystones()[1]
Example #18
0
def local_pystone():
    return pystone.pystones(loops=pystone.LOOPS)
Example #19
0
#!/usr/bin/env python
#-*-coding:utf-8-*-
import time
from test import pystone
benchtimes,pystones=pystone.pystones()
#将消耗时间转化为pystones数
def seconds_to_pystones(seconds):
    return (pystones*seconds)
stats= {}
def duration(name='stats',stats=stats):
    def _duration(func):
        def __duration(*args,**kw):
            start_time=time.time()
            try:
                return func(*args,**kw)
            finally:
                total=time.time()-start_time
                kstones=seconds_to_pystones(total)
                stats[name]=total,kstones
        return __duration
    return _duration
@duration()
def mytest():
    print 'ok'
if __name__=="__main__":
    mytest()
    print stats

Example #20
0
# file: pystone_converter.py

"""Convert seconds to kilo pystones."""

from test import pystone

BENCHMARK_TIME, PYSTONES = pystone.pystones()


def kpystone_from_seconds(seconds):
    """Convert seconds to kilo pystones."""
    return (seconds * PYSTONES) / 1e3

if __name__ == '__main__':

    def test():
        """Show how it works
        """
        print
        print '%10s %10s' % ('seconds', 'kpystones')
        print
        for seconds in [0.1, 0.5, 1.0, 2.0, 5.0]:
            print ('%10.5f %10.5f' % (seconds, kpystone_from_seconds(seconds)))

    test()
Example #21
0
 def pystonesPerSecond(self):
     """How many pystones are equivalent to one second on this machine"""
     if self._pystones_per_second == None:
         self._pystones_per_second = pystone.pystones(pystone.LOOPS/10)[1]
     return self._pystones_per_second
Example #22
0
import time
import sys
from test import pystone
from guppy import hpy

benchtime, stones = pystone.pystones()

def secs_to_kstones(seconds):
    return (stones*seconds) / 1000 
stats = {}
if sys.platform == 'win32':
    timer = time.clock
else:
    timer = time.time
    
def profile(name='stats', stats=stats):
    """Calculates a duration and a memory size."""
    def _profile(function):
        def __profile(*args, **kw):
            start_time = timer()
            profiler = hpy()
            profiler.setref()
            # 12 corresponds to the initial memory size
            # after a setref call
            start = profiler.heap().size + 12
            try:
                return function(*args, **kw)
            finally:
                total = timer() - start_time
                kstones = secs_to_kstones(total)
                memory = profiler.heap().size - start
Example #23
0
import time
import sys
from test import pystone
from guppy import hpy

benchtime, stones = pystone.pystones()


def secs_to_kstones(seconds):
    return (stones * seconds) / 1000


stats = {}


def reset_stats():
    stats.clear()


def print_stats():
    template = '%s : %.2f kstones, %.3f secondes, %.3d bytes'
    for key, v in stats.items():
        print template % (key, v['stones'], v['time'], v['memory'])


if sys.platform == 'win32':
    timer = time.clock
else:
    timer = time.time

Example #24
0
 def __init__(self, function):        
     from test import pystone
     self.function = function
     if not hasattr(Pystone_Test, "pystones_per_second"):
         Pystone_Test.pystones_per_second = pystone.pystones(pystone.LOOPS)
Example #25
0
 def CpuWork():
     pystones(self.pyStonesPerUnit)
Example #26
0
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
# 
## end license ##

# Module test.pystone may interfere with default test package
# With this code we temporarily move the beginning of the PYTHON_PATH aside to
# import the good test module.
from sys import path
import sys
temppath = []
def pystones(*args, **kwargs):
    from warnings import warn
    warn("Python module 'test.pystone' not available. Will assume T=1.0")
    return 1.0, "ignored"
while len(path) > 0:
    try:
        if 'test' in sys.modules:
            del sys.modules['test']
        from test.pystone import pystones
        break
    except ImportError:
        temppath.append(path[0])
        del path[0]
    
T, p = pystones(loops=50000)
print 'T=%.1fs' % T

for temp in reversed(temppath):
    path.insert(0, temp)
del temppath
Example #27
0
# Module test.pystone may interfere with default test package
# With this code we temporarily move the beginning of the PYTHON_PATH aside to
# import the good test module.
from sys import path
import sys
temppath = []


def pystones(*args, **kwargs):
    from warnings import warn
    warn("Python module 'test.pystone' not available. Will assume T=1.0")
    return 1.0, "ignored"


while len(path) > 0:
    try:
        if 'test' in sys.modules:
            del sys.modules['test']
        from test.pystone import pystones
        break
    except ImportError:
        temppath.append(path[0])
        del path[0]

T, p = pystones(loops=50000)
print 'T=%.1fs' % T

for temp in reversed(temppath):
    path.insert(0, temp)
del temppath
Example #28
0
from test import pystone
pystone.pystones(1)
for _ in xrange(10):
    _, stones = pystone.pystones(50000)
    # Sometimes d8 produces zero or negative pystones/second, due to the
    # JS JIT warmup interfering with the way pystone tries to adjust for
    # null loop time.  We just replace it with small positive value.
    print max(stones, 1)
Example #29
0
 def test_pystone(self):
     print "PYSTONE RESULT (time,score) : %r" % (pystone.pystones(),)
Example #30
0
def seconds_to_pystones(seconds):
    benchtime, pystones = pystone.pystones()
    return (pystones * seconds) / 1000
def _pystone_calibration():
    global _pystone_calibration_mark
    if not _pystone_calibration_mark:
        _pystone_calibration_mark = pystone.pystones(loops=pystone.LOOPS)
    return _pystone_calibration_mark
# file: pystone_converter.py
"""Convert seconds to kilo pystones."""

from test import pystone

BENCHMARK_TIME, PYSTONES = pystone.pystones()


def kpystone_from_seconds(seconds):
    """Convert seconds to kilo pystones."""
    return (seconds * PYSTONES) / 1e3


if __name__ == '__main__':

    def test():
        """Show how it works
        """
        print
        print '%10s %10s' % ('seconds', 'kpystones')
        print
        for seconds in [0.1, 0.5, 1.0, 2.0, 5.0]:
            print('%10.5f %10.5f' % (seconds, kpystone_from_seconds(seconds)))

    test()