3 from twisted.protocols import basic
5 class CollectingLineReceiver(basic.LineReceiver):
8 self.lineReceived = self.lines.append
10 def deliver(proto, chunks):
11 map(proto.dataReceived, chunks)
13 def benchmark(chunkSize, lineLength, numLines):
14 bytes = ('x' * lineLength + '\r\n') * numLines
15 chunkCount = len(bytes) / chunkSize + 1
17 for n in xrange(chunkCount):
18 chunks.append(bytes[n*chunkSize:(n+1)*chunkSize])
19 assert ''.join(chunks) == bytes, (chunks, bytes)
20 p = CollectingLineReceiver()
26 assert bytes.splitlines() == p.lines, (bytes.splitlines(), p.lines)
28 print 'chunkSize:', chunkSize,
29 print 'lineLength:', lineLength,
30 print 'numLines:', numLines,
31 print 'CPU Time: ', after - before
36 for numLines in 100, 1000:
37 for lineLength in (10, 100, 1000):
38 for chunkSize in (1, 500, 5000):
39 benchmark(chunkSize, lineLength, numLines)
41 for numLines in 10000, 50000:
42 for lineLength in (1000, 2000):
43 for chunkSize in (51, 500, 5000):
44 benchmark(chunkSize, lineLength, numLines)
46 if __name__ == '__main__':