akrennmair/gopcap — pull request #20 by gconnell (2012-12-11 01:36:06+00:00)
Title: Speedcopy

Speed up the copy of packet data from C into Go, using C.GoBytes. Also avoid a copy of the packet header struct. Together, this seems to reduce packet read speed by ~50%

Added a benchmark binary for testing this change.

Old:
(/tmp/bench is tools/benchmark with the old code)
gconnell@zombie-test1.mtv:/$ /tmp/bench -file /tmp/foo
Took 3.334896s to process 1000000 packets, 3.334us per packet, 0 nil packets
gconnell@zombie-test1.mtv:/$ /tmp/bench -file /tmp/foo
Took 3.329675s to process 1000000 packets, 3.329us per packet, 0 nil packets

New:
(/tmp/bench2 is tools/benchmark with the new code)
gconnell@zombie-test1.mtv:/$ /tmp/bench2 -file /tmp/foo
Took 1.588695s to process 1000000 packets, 1.588us per packet, 0 nil packets
gconnell@zombie-test1.mtv:/$ /tmp/bench2 -file /tmp/foo
Took 1.580306s to process 1000000 packets, 1.58us per packet, 0 nil packets

About a 50% reduction in the initial packet copy. This seemed to work pretty
repeatably.