-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moved benches from inside pnet_packet/src/ethernet.rs to pnet_packet/…
…benches/packet_benchmarks.rs; added inlining to pnet_macros to increase speed of parsing data into packet
- Loading branch information
Harry Thomas
committed
Apr 19, 2022
1 parent
da0124d
commit 9ab461b
Showing
5 changed files
with
90 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#![feature(test)] | ||
extern crate test; | ||
use test::{Bencher, black_box}; | ||
|
||
use pnet_packet::ethernet::EthernetPacket; | ||
use pnet_packet::ethernet::MutableEthernetPacket; | ||
use pnet_packet::ipv4::MutableIpv4Packet; | ||
use pnet_base::MacAddr; | ||
use pnet_packet::Packet; | ||
use pnet_packet::ipv4::Ipv4Packet; | ||
|
||
#[bench] | ||
fn bench_packet_new_constructor(b: &mut Bencher) { | ||
let buffer = vec![0; 20]; | ||
b.iter(|| EthernetPacket::new(black_box(&buffer)).unwrap()); | ||
} | ||
|
||
#[bench] | ||
fn bench_packet_get_source(b: &mut Bencher) { | ||
let buffer = vec![0; 20]; | ||
let packet = EthernetPacket::new(&buffer).unwrap(); | ||
b.iter(|| black_box(packet.get_source())); | ||
} | ||
|
||
#[bench] | ||
fn bench_packet_set_source_black_box(b: &mut Bencher) { | ||
let mut buffer = vec![0; 20]; | ||
let mut packet = MutableEthernetPacket::new(&mut buffer).unwrap(); | ||
let mac = MacAddr::new(1, 2, 3, 4, 5, 6); | ||
b.iter(|| packet.set_source(black_box(mac))); | ||
} | ||
|
||
#[bench] | ||
fn bench_packet_mutable_to_immutable(b: &mut Bencher) { | ||
let mut buffer = vec![0; 20]; | ||
let mut packet = MutableEthernetPacket::new(&mut buffer).unwrap(); | ||
b.iter(|| black_box(packet.to_immutable())); | ||
} | ||
|
||
#[bench] | ||
fn bench_packet_immutable_to_immutable(b: &mut Bencher) { | ||
let mut buffer = vec![0; 20]; | ||
let mut packet = EthernetPacket::new(&mut buffer).unwrap(); | ||
b.iter(|| black_box(packet.to_immutable())); | ||
} | ||
|
||
#[bench] | ||
fn bench_ipv4_parsing(b: &mut Bencher) { | ||
let data = hex::decode("000c291ce319ecf4bbd93e7d08004500002e1b6540008006cd76c0a8c887c0a8c8151a3707d0dd6abb2b1f5fd25150180402120f000068656c6c6f0a").unwrap(); | ||
let ethernet = EthernetPacket::new(&data).unwrap(); | ||
let payload = ethernet.payload().clone(); | ||
b.iter(|| | ||
Ipv4Packet::new(black_box(&payload)) | ||
); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters