File: test-perf2.py

package info (click to toggle)
python-dpkt 1.6%2Bsvn54-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, squeeze, wheezy
  • size: 448 kB
  • ctags: 1,950
  • sloc: python: 5,136; makefile: 71
file content (26 lines) | stat: -rw-r--r-- 582 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/env python

import dpkt
import time, unittest

class TestPerf(unittest.TestCase):
    rounds = 10000

    def setUp(self):
        self.start = time.time()
    def tearDown(self):
        print self.rounds / (time.time() - self.start), 'rounds/s'

    def test_pack(self):
        for i in xrange(self.rounds):
            str(dpkt.ip.IP())
        print 'pack:',

    def test_unpack(self):
        buf = str(dpkt.ip.IP())
        for i in xrange(self.rounds):
            dpkt.ip.IP(buf)
        print 'unpack:',
        
if __name__ == '__main__':
    unittest.main()