In this section you can find some benchmarks which aim at comparing how well does libtins work compared to other libraries that serve its same purpose.
Every benchmark was executed on a computer with the following specs:
Benchmarks were executed using the following libraries:
If you want to reproduce the benchmarks, you can download the benchmark project on github.
Note that the libtins, libcrafter and libpcap test cases were compiled using C++11(using the -std=c++11 gcc switch).
Note: the scapy benchmarks look like it takes almost the same time as the impacket ones, but it actually doesn't. In fact, it takes so much time that the maximum Y-axis value had to be restricted. Otherwise the rest of the bars couldn't almost be seen. If you hover over each bar, you will see the actual times in seconds.
In this first benchmark, I generated a pcap file containing 500000 packets generated, using the following template:
That means the pcap file will contain 500000 packets, all of them will have an Ethernet II frame, an IP datagrams, a TCP segment, and a payload of 742 bytes at the end of the PDU chain.
The test case developed for every library basically opens the generated
pcap file and interprets each of the packets. Here "interprets" means
creating a the corresponding Ethernet
object for each library,
and all of the following PDU
s.
The libpcap test is used as a base case; it simply reads the pcap file and counts the number of packets in it. No library that interprets packets should be faster than libpcap, since all of them use it implicitly to read the pcap file.
The benchmark results were the following:
Library | Time taken(seconds) | Packets per second |
---|---|---|
libpcap | 0.141 | 3546099 |
libtins | 0.273 | 1831501 |
pcapplusplus | 0.38 | 1315789 |
dpkt | 8.132 | 61485 |
libcrafter | 12.209 | 40953 |
impacket | 18.5 | 27027 |
scapy | 187.082 | 2672 |
The first column indicates the library tested. The second column indicates the time taken for that library to parse the entire file, and the last one how many packets per second did the library interpret.
This benchmark is very similar to the one above, but in this one, I added
TCP
options to the TCP
segment. This is the code
that generates each packet:
The results of this benchmark were the following:
Library | Time taken(seconds) | Packets per second |
---|---|---|
libpcap | 0.145 | 3448275 |
libtins | 0.364 | 1373626 |
pcapplusplus | 0.385 | 1298701 |
dpkt | 8.508 | 58768 |
libcrafter | 20.199 | 24753 |
impacket | 44.491 | 11238 |
scapy | 194.543 | 2570 |
This benchmark measures the speed at which each library can parse DNS packets. The input pcap file consists of 500000 copies of the following packet:
As you can see, there are three domain names present and two of them use compression. For this test case, the codes used not only parse the packet and construct the appropriate DNS object when required, but also iterate over both the question and answer records so as to force the libraries to parse the domain names included in them.
The results of this benchmark were the following:
Library | Time taken(seconds) | Packets per second |
---|---|---|
libpcap | 0.036 | 13888888 |
libtins | 0.391 | 1278772 |
pcapplusplus | 0.724 | 690607 |
libcrafter | 13.524 | 36971 |
dpkt | 23.319 | 21441 |
impacket | 36.487 | 13703 |
scapy | 374.637 | 1334 |
As you can see, libtins is faster at interpreting packets than the rest of the libraries tested. Moreover, it has very little overhead compared to libpcap, which does not perform any packet interpretation at all.
More benchmarks will be added soon.