HARD REAL TIME PYTHON

James Mills prologic at shortcircuit.net.au
Sat Oct 11 08:53:44 CEST 2008


On 10/7/08, James Mills <prologic at shortcircuit.net.au> wrote:
>  I shall do some latency benchmarks ok :)

Out of curiosity I modifed my bench marking tool
for my event/component library (pymills) and here
are the results:

~/pymills/examples/event
$ ./bench.py -m latency -t 10
Setting up latency Test...
Latency: 0.38 ms
Latency: 0.02 ms
Latency: 0.02 ms
Latency: 0.02 ms
Latency: 0.02 ms
Latency: 0.02 ms
Latency: 0.02 ms
Latency: 0.02 ms
Latency: 0.02 ms
Latency: 0.02 ms

Total Events: 27 (3/s after 10.00s)

To measure this, I created a new component
and mode (-m/--mode == "latency"):

<code>
class LatencyTest(Component):

   t = None

   @listener("received")
   def onRECEIVED(self, message=""):
      print "Latency: %0.2f ms" % ((time.time() - self.t) * 1000)
      time.sleep(1)
      self.push(Hello("hello"), "hello", self.channel)

   @listener("hello")
   def onHELLO(self, message=""):
      self.t = time.time()
      self.push(Received(message), "received", self.channel)
</code>

NB: The measured latency of "pushing" a single event around the system
and reacting to it is less than 1ms, even less than 0.1 ms.

Someone will probably point out that this measure
isn't much good as it measures only for a single
event in the queue, so I also added a new option
to my bench marking tool (-f/--fill) to allow me
to set a "filler" of dummy events in the queue
that just get flushed out (but not processed)
by any event handler. Here are the results
from a filler of 100 (-f 100):

$ ./bench.py -m latency -t 10 -f 100
Setting up latency Test...
Latency: 1.52 ms
Latency: 0.78 ms
Latency: 0.76 ms
Latency: 0.76 ms
Latency: 0.77 ms
Latency: 0.77 ms
Latency: 0.76 ms
Latency: 0.76 ms
Latency: 0.76 ms
Latency: 0.77 ms

Total Events: 2027 (203/s after 10.02s)

cheers
James

-- 
--
-- "Problems are solved by method"



More information about the Python-list mailing list