Skip to content

Commit

Permalink
benches: adjust for the new benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-abramov committed Dec 13, 2024
1 parent 596fe8a commit 4eb13ac
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
5 changes: 4 additions & 1 deletion benches/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ fn benchmark(c: &mut Criterion) {
for i in 0_u64..100_000 {
writer
.send(match i {
_ if i % 3 == 0 => Message::Binary(i.to_le_bytes().into()),
_ if i % 3 == 0 => {
let data: Vec<u8> = i.to_le_bytes().into();
Message::Binary(data.into())
}
_ => Message::Text(format!("{{\"id\":{i}}}")),
})
.unwrap();
Expand Down
5 changes: 4 additions & 1 deletion benches/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ fn benchmark(c: &mut Criterion) {
b.iter(|| {
for i in 0_u64..100_000 {
let msg = match i {
_ if i % 3 == 0 => Message::Binary(i.to_le_bytes().into()),
_ if i % 3 == 0 => {
let data: Vec<u8> = i.to_le_bytes().into();
Message::Binary(data.into())
}
_ => Message::Text(format!("{{\"id\":{i}}}")),
};
ws.write(msg).unwrap();
Expand Down
3 changes: 2 additions & 1 deletion src/protocol/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,8 @@ impl<'s> From<&'s str> for Message {

impl<'b> From<&'b [u8]> for Message {
fn from(data: &'b [u8]) -> Self {
Message::binary(data.to_vec())
let data: Vec<u8> = data.into();
Message::binary(data)
}
}

Expand Down

0 comments on commit 4eb13ac

Please sign in to comment.