2012-06-06 18:42:25 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2015-03-11 16:48:11 +00:00
|
|
|
import time
|
|
|
|
import unittest
|
2012-06-06 18:42:25 +00:00
|
|
|
import dpkt
|
2015-03-11 16:48:11 +00:00
|
|
|
|
2012-06-06 18:42:25 +00:00
|
|
|
|
|
|
|
class TestPerf(unittest.TestCase):
|
|
|
|
rounds = 10000
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.start = time.time()
|
2015-03-11 16:48:11 +00:00
|
|
|
|
2012-06-06 18:42:25 +00:00
|
|
|
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()
|