Skip to content

Commit

Permalink
Update the Rust deserialization benchmark to not include message deal…
Browse files Browse the repository at this point in the history
…location time
  • Loading branch information
stepchowfun committed Jun 20, 2024
1 parent 82c15f4 commit 8b9f829
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -648,14 +648,14 @@ One benchmark serializes and deserializes a large message containing several hun
| | Rust | TypeScript |
| ----------------------------------- | ------------ | ------------ |
| **Per-thread serialization rate** | 11.663 GiB/s | 11.092 GiB/s |
| **Per-thread deserialization rate** | 6.030 GiB/s | 7.915 GiB/s |
| **Per-thread deserialization rate** | 7.568 GiB/s | 7.915 GiB/s |

Another benchmark repeatedly serializes and deserializes a pathological message containing many small and deeply nested values:

| | Rust | TypeScript |
| ----------------------------------- | ------------- | ------------ |
| **Per-thread serialization rate** | 688.198 MiB/s | 48.992 MiB/s |
| **Per-thread deserialization rate** | 290.701 MiB/s | 2.341 MiB/s |
| **Per-thread deserialization rate** | 303.313 MiB/s | 2.341 MiB/s |

These benchmarks represent two extremes. Real-world performance will be somewhere in the middle.

Expand Down
8 changes: 6 additions & 2 deletions benchmarks/rust/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod types;

use {
std::{f64::consts::PI, io, time::Instant},
std::{f64::consts::PI, io, mem::forget, time::Instant},
types::{
types::{ChoiceOut, MessageIn, MessageOut, StructIn, StructOut},
Deserialize, Serialize,
Expand Down Expand Up @@ -94,7 +94,11 @@ fn benchmark<T: Serialize, U: Deserialize>(message: &T, iterations: usize) -> io

for i in 0..iterations {
let offset = message_size * i;
U::deserialize(&buffer[offset..offset + message_size])?;
let message = U::deserialize(&buffer[offset..offset + message_size])?;

// Don't deallocate the memory in this loop, since that isn't what the benchmark is
// intended to measure.
forget(message);
}

let deserialization_duration = deserialization_instant.elapsed();
Expand Down

0 comments on commit 8b9f829

Please sign in to comment.