Skip to content

Commit

Permalink
fix rust bench
Browse files Browse the repository at this point in the history
  • Loading branch information
QuentinGruber committed Nov 25, 2023
1 parent 35727d4 commit bf1784b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
32 changes: 16 additions & 16 deletions benches/lib-bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ fn soeprotocol_pack_benchmarks(c: &mut Criterion) {
c.bench_function("session_request_pack", |b| {
b.iter(|| {
soeprotocol_class.pack(
"SessionRequest".to_owned(),
SoeOpcode::SessionRequest,
black_box(session_request_to_pack.to_string()),
)
})
Expand All @@ -211,7 +211,7 @@ fn soeprotocol_pack_benchmarks(c: &mut Criterion) {
c.bench_function("session_reply_to_pack", |b| {
b.iter(|| {
soeprotocol_class.pack(
"SessionReply".to_owned(),
SoeOpcode::SessionReply,
black_box(session_reply_to_pack.to_string()),
)
})
Expand All @@ -222,12 +222,12 @@ fn soeprotocol_pack_benchmarks(c: &mut Criterion) {
b.iter(|| soeprotocol_class.pack_session_reply_object(session_reply_to_pack_object.clone()))
});
c.bench_function("ping_to_pack", |b| {
b.iter(|| soeprotocol_class.pack("Ping".to_owned(), black_box(ping_to_pack.to_string())))
b.iter(|| soeprotocol_class.pack(SoeOpcode::Ping, black_box(ping_to_pack.to_string())))
});
c.bench_function("outoforder_to_pack", |b| {
b.iter(|| {
soeprotocol_class.pack(
"OutOfOrder".to_owned(),
SoeOpcode::OutOfOrder,
black_box(outoforder_to_pack.to_string()),
)
})
Expand All @@ -238,7 +238,7 @@ fn soeprotocol_pack_benchmarks(c: &mut Criterion) {
b.iter(|| soeprotocol_class.pack_out_of_order_object(outoforder_to_pack_object.clone()))
});
c.bench_function("ack_to_pack", |b| {
b.iter(|| soeprotocol_class.pack("Ack".to_owned(), black_box(ack_to_pack.to_string())))
b.iter(|| soeprotocol_class.pack(SoeOpcode::Ack, black_box(ack_to_pack.to_string())))
});
let ack_to_pack_object = soeprotocol_class.get_ack_object(ack_to_pack.to_string());
c.bench_function("ack_to_pack_from_object", |b| {
Expand All @@ -247,7 +247,7 @@ fn soeprotocol_pack_benchmarks(c: &mut Criterion) {
c.bench_function("multi_to_pack", |b| {
b.iter(|| {
soeprotocol_class.pack(
"MultiPacket".to_owned(),
SoeOpcode::MultiPacket,
black_box(multi_to_pack.to_string()),
)
})
Expand All @@ -257,7 +257,7 @@ fn soeprotocol_pack_benchmarks(c: &mut Criterion) {
b.iter(|| soeprotocol_class.pack_multi_object(multi_to_pack_object.clone()))
});
c.bench_function("data_to_pack", |b| {
b.iter(|| soeprotocol_class.pack("Data".to_owned(), black_box(data_to_pack.to_string())))
b.iter(|| soeprotocol_class.pack(SoeOpcode::Data, black_box(data_to_pack.to_string())))
});
let data_to_pack_object = soeprotocol_class.get_data_object(data_to_pack.to_string());
c.bench_function("data_to_pack_from_object", |b| {
Expand All @@ -266,7 +266,7 @@ fn soeprotocol_pack_benchmarks(c: &mut Criterion) {
c.bench_function("data_fragment_to_pack", |b| {
b.iter(|| {
soeprotocol_class.pack(
"DataFragment".to_owned(),
SoeOpcode::DataFragment,
black_box(data_fragment_to_pack.to_string()),
)
})
Expand All @@ -282,48 +282,48 @@ fn soeprotocol_pack_benchmarks(c: &mut Criterion) {
c.bench_function("session_request_pack_crc", |b| {
b.iter(|| {
soeprotocol_class.pack(
"SessionRequest".to_owned(),
SoeOpcode::SessionRequest,
black_box(session_request_to_pack.to_string()),
)
})
});
c.bench_function("session_reply_to_pack_crc", |b| {
b.iter(|| {
soeprotocol_class.pack(
"SessionReply".to_owned(),
SoeOpcode::SessionReply,
black_box(session_reply_to_pack.to_string()),
)
})
});
c.bench_function("ping_to_pack_crc", |b| {
b.iter(|| soeprotocol_class.pack("Ping".to_owned(), black_box(ping_to_pack.to_string())))
b.iter(|| soeprotocol_class.pack(SoeOpcode::Ping, black_box(ping_to_pack.to_string())))
});
c.bench_function("outoforder_to_pack_crc", |b| {
b.iter(|| {
soeprotocol_class.pack(
"OutOfOrder".to_owned(),
SoeOpcode::OutOfOrder,
black_box(outoforder_to_pack.to_string()),
)
})
});
c.bench_function("ack_to_pack_crc", |b| {
b.iter(|| soeprotocol_class.pack("Ack".to_owned(), black_box(ack_to_pack.to_string())))
b.iter(|| soeprotocol_class.pack(SoeOpcode::Ack, black_box(ack_to_pack.to_string())))
});
c.bench_function("multi_to_pack_crc", |b| {
b.iter(|| {
soeprotocol_class.pack(
"MultiPacket".to_owned(),
SoeOpcode::MultiPacket,
black_box(multi_to_pack.to_string()),
)
})
});
c.bench_function("data_to_pack_crc", |b| {
b.iter(|| soeprotocol_class.pack("Data".to_owned(), black_box(data_to_pack.to_string())))
b.iter(|| soeprotocol_class.pack(SoeOpcode::Data, black_box(data_to_pack.to_string())))
});
c.bench_function("data_fragment_to_pack_crc", |b| {
b.iter(|| {
soeprotocol_class.pack(
"DataFragment".to_owned(),
SoeOpcode::DataFragment,
black_box(data_fragment_to_pack.to_string()),
)
})
Expand Down
18 changes: 9 additions & 9 deletions src/soeprotocol_packets_structs.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct SessionRequestPacket {
pub session_id: u32,
pub crc_length: u32,
Expand All @@ -9,7 +9,7 @@ pub struct SessionRequestPacket {
pub error: Option<bool>, // used internnaly to identify deserialization errors
}

#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct SessionReplyPacket {
pub session_id: u32,
pub crc_seed: u32,
Expand All @@ -20,7 +20,7 @@ pub struct SessionReplyPacket {
pub error: Option<bool>, // used internnaly to identify deserialization errors
}

#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct NetStatusReplyPacket {
pub client_tick_count: u16,
pub server_tick_count: u32,
Expand All @@ -33,7 +33,7 @@ pub struct NetStatusReplyPacket {
pub error: Option<bool>, // used internnaly to identify deserialization errors
}

#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct MultiPackablePacket {
// should contain all possible field for a multiPackable packet
pub name: String,
Expand All @@ -42,22 +42,22 @@ pub struct MultiPackablePacket {
pub sequence: u16,
}

#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct DataPacket {
pub data: Vec<u8>,
pub sequence: u16,
#[serde(skip_serializing_if = "Option::is_none")]
pub error: Option<bool>, // used internnaly to identify deserialization errors
}

#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct AckPacket {
pub sequence: u16,
#[serde(skip_serializing_if = "Option::is_none")]
pub error: Option<bool>, // used internnaly to identify deserialization errors
}

#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct NetStatusRequestPacket {
pub client_tick_count: u16,
pub last_client_update: u32,
Expand All @@ -72,7 +72,7 @@ pub struct NetStatusRequestPacket {
pub error: Option<bool>, // used internnaly to identify deserialization errors
}

#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct SubBasePacket {
pub name: String,
#[serde(skip_serializing_if = "Option::is_none")]
Expand All @@ -83,7 +83,7 @@ pub struct SubBasePacket {
pub error: Option<bool>, // used internnaly to identify deserialization errors
}

#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct SubBasePackets {
pub sub_packets: Vec<Vec<u8>>,
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down

0 comments on commit bf1784b

Please sign in to comment.