Package SimPy :: Module testRT_Behavior |
[hide private]
[frames] | no frames]

# Source Code for Module SimPy.testRT_Behavior

     1  #!/usr / bin / env python
     2  from SimPy.SimulationRT import *
     3  """testRT_Behavior_OO.py
     4  Tests SimulationRT for degree to which simulation time
     5  and wallclock time can be synchronized.
     6
     7  Non-OO API.
     8  """
     9  # $Revision: 295 $ $Date: 2009-03-30 14:26:20 +0200 (Mo, 30 Mrz 2009) $
    10
    11  print "Under test: SimulationRT.py %s"% version
    12  __version__ = '2.0 $Revision: 295 $ $Date: 2009-03-30 14:26:20 +0200 (Mo, 30 Mrz 2009) $ '
    13  print 'testRT_Behavior.py %s'%__version__
    14
    15 -class Ticker(Process):
    16 -    def tick(self):
    17          self.timing = []
    18          while True:
    19              yield hold,self,1
    20              tSim = now()
    21              tRT = rtnow()
    22              self.timing.append((tSim,tRT))
    23
    24  initialize()
    25  t=Ticker()
    26  activate(t,t.tick())
    27  simulate(until=10,real_time=True,rel_speed=1)
    28
    29  print "Speed ratio set: 1"
    30  print "------------------"
    31  for tSim,tRT in t.timing:
    32      print "tSim:%s, tRT:%s, speed ratio:%s"%(tSim,tRT,tSim/tRT)
    33
    34  initialize()
    35  t=Ticker()
    36  activate(t,t.tick())
    37  simulate(until=10,real_time=True,rel_speed=5)
    38
    39  print
    40  print "Speed ratio set: 5"
    41  print "------------------"
    42  for tSim,tRT in t.timing:
    43      print "tSim:%s, tRT:%s, speed ratio:%s"%(tSim,tRT,tSim/tRT)
    44