Package SimPy :: Module testRT_Behavior

[hide private]
[frames] | no frames]

# Source Code for Module SimPy.testRT_Behavior

     1  #!/usr / bin / env python

     2  # coding=utf-8

     3  from SimPy.SimulationRT import *
     4  """testRT_Behavior_OO.py

     5  Tests SimulationRT for degree to which simulation time

     6  and wallclock time can be synchronized.

     7

     8  Non-OO API.

     9  """
    10  # $Revision: 419 $ $Date: 2010-03-29 16:03:43 +0200 (Mon, 29 Mar 2010) $

    11

    12  print "Under test: SimulationRT.py %s"% version
    13  __version__ = '2.1 $Revision: 419 $ $Date: 2010-03-29 16:03:43 +0200 (Mon, 29 Mar 2010) $ '
    14  print 'testRT_Behavior.py %s'%__version__
    15

    16 -class Ticker(Process):
    17 -    def tick(self):
    18          self.timing = []
    19          while True:
    20              yield hold,self,1
    21              tSim = now()
    22              tRT = rtnow()
    23              self.timing.append((tSim,tRT))
    24

    25  initialize()
    26  t=Ticker()
    27  activate(t,t.tick())
    28  simulate(until=10,real_time=True,rel_speed=1)
    29

    30  print "Speed ratio set: 1"
    31  print "------------------"
    32  for tSim,tRT in t.timing:
    33      print "tSim:%s, tRT:%s, speed ratio:%s"%(tSim,tRT,tSim/tRT)
    34

    35  initialize()
    36  t=Ticker()
    37  activate(t,t.tick())
    38  simulate(until=10,real_time=True,rel_speed=5)
    39

    40  print
    41  print "Speed ratio set: 5"
    42  print "------------------"
    43  for tSim,tRT in t.timing:
    44      print "tSim:%s, tRT:%s, speed ratio:%s"%(tSim,tRT,tSim/tRT)
    45