-
Couldn't load subscription status.
- Fork 210
Experimental Draft: Rkyv #1034
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Experimental Draft: Rkyv #1034
Changes from all commits
34ba909
d98681b
3705fc5
fed3478
cf2dfb1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| #![feature(test)] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Benches are run upon commit in my dev repo, so I'm not sure if we'll blow up GitHub by adding so many new benches. We can try. The benchmarks are not run in the official repo which is named |
||
| #![cfg(all(feature = "rkyv", feature = "serde"))] | ||
|
|
||
| //! Benchmark comparing rkyv and serde serialization performance | ||
| extern crate test; | ||
|
|
||
| use rhai::Dynamic; | ||
| use test::Bencher; | ||
|
|
||
| // ============================================================================ | ||
| // Integer Benchmarks | ||
| // ============================================================================ | ||
|
|
||
| #[bench] | ||
| fn bench_rkyv_serialize_int(bench: &mut Bencher) { | ||
| let value = Dynamic::from(42_i64); | ||
| bench.iter(|| { | ||
| let bytes = rhai::rkyv::to_bytes(&value).unwrap(); | ||
| test::black_box(bytes); | ||
| }); | ||
| } | ||
|
|
||
| #[bench] | ||
| fn bench_serde_json_serialize_int(bench: &mut Bencher) { | ||
| let value = Dynamic::from(42_i64); | ||
| bench.iter(|| { | ||
| let json = serde_json::to_string(&value).unwrap(); | ||
| test::black_box(json); | ||
| }); | ||
| } | ||
|
|
||
| #[bench] | ||
| fn bench_rkyv_deserialize_int(bench: &mut Bencher) { | ||
| let value = Dynamic::from(42_i64); | ||
| let bytes = rhai::rkyv::to_bytes(&value).unwrap(); | ||
|
|
||
| bench.iter(|| { | ||
| let restored: Dynamic = rhai::rkyv::from_bytes_owned(&bytes).unwrap(); | ||
| test::black_box(restored); | ||
| }); | ||
| } | ||
|
|
||
| #[bench] | ||
| fn bench_serde_json_deserialize_int(bench: &mut Bencher) { | ||
| let value = Dynamic::from(42_i64); | ||
| let json = serde_json::to_string(&value).unwrap(); | ||
|
|
||
| bench.iter(|| { | ||
| let restored: Dynamic = serde_json::from_str(&json).unwrap(); | ||
| test::black_box(restored); | ||
| }); | ||
| } | ||
|
|
||
| #[bench] | ||
| fn bench_rkyv_roundtrip_int(bench: &mut Bencher) { | ||
| let value = Dynamic::from(42_i64); | ||
| bench.iter(|| { | ||
| let bytes = rhai::rkyv::to_bytes(&value).unwrap(); | ||
| let restored: Dynamic = rhai::rkyv::from_bytes_owned(&bytes).unwrap(); | ||
| test::black_box(restored); | ||
| }); | ||
| } | ||
|
|
||
| #[bench] | ||
| fn bench_serde_json_roundtrip_int(bench: &mut Bencher) { | ||
| let value = Dynamic::from(42_i64); | ||
| bench.iter(|| { | ||
| let json = serde_json::to_string(&value).unwrap(); | ||
| let restored: Dynamic = serde_json::from_str(&json).unwrap(); | ||
| test::black_box(restored); | ||
| }); | ||
| } | ||
|
|
||
| // ============================================================================ | ||
| // String Benchmarks | ||
| // ============================================================================ | ||
|
|
||
| #[bench] | ||
| fn bench_rkyv_serialize_string(bench: &mut Bencher) { | ||
| let value = Dynamic::from("Hello, World! This is a benchmark string."); | ||
| bench.iter(|| { | ||
| let bytes = rhai::rkyv::to_bytes(&value).unwrap(); | ||
| test::black_box(bytes); | ||
| }); | ||
| } | ||
|
|
||
| #[bench] | ||
| fn bench_serde_json_serialize_string(bench: &mut Bencher) { | ||
| let value = Dynamic::from("Hello, World! This is a benchmark string."); | ||
| bench.iter(|| { | ||
| let json = serde_json::to_string(&value).unwrap(); | ||
| test::black_box(json); | ||
| }); | ||
| } | ||
|
|
||
| #[bench] | ||
| fn bench_rkyv_deserialize_string(bench: &mut Bencher) { | ||
| let value = Dynamic::from("Hello, World! This is a benchmark string."); | ||
| let bytes = rhai::rkyv::to_bytes(&value).unwrap(); | ||
|
|
||
| bench.iter(|| { | ||
| let restored: Dynamic = rhai::rkyv::from_bytes_owned(&bytes).unwrap(); | ||
| test::black_box(restored); | ||
| }); | ||
| } | ||
|
|
||
| #[bench] | ||
| fn bench_serde_json_deserialize_string(bench: &mut Bencher) { | ||
| let value = Dynamic::from("Hello, World! This is a benchmark string."); | ||
| let json = serde_json::to_string(&value).unwrap(); | ||
|
|
||
| bench.iter(|| { | ||
| let restored: Dynamic = serde_json::from_str(&json).unwrap(); | ||
| test::black_box(restored); | ||
| }); | ||
| } | ||
|
|
||
| // ============================================================================ | ||
| // Float Benchmarks | ||
| // ============================================================================ | ||
|
|
||
| #[cfg(not(feature = "no_float"))] | ||
| #[bench] | ||
| fn bench_rkyv_roundtrip_float(bench: &mut Bencher) { | ||
| let value = Dynamic::from(3.14159265358979_f64); | ||
| bench.iter(|| { | ||
| let bytes = rhai::rkyv::to_bytes(&value).unwrap(); | ||
| let restored: Dynamic = rhai::rkyv::from_bytes_owned(&bytes).unwrap(); | ||
| test::black_box(restored); | ||
| }); | ||
| } | ||
|
|
||
| #[cfg(not(feature = "no_float"))] | ||
| #[bench] | ||
| fn bench_serde_json_roundtrip_float(bench: &mut Bencher) { | ||
| let value = Dynamic::from(3.14159265358979_f64); | ||
| bench.iter(|| { | ||
| let json = serde_json::to_string(&value).unwrap(); | ||
| let restored: Dynamic = serde_json::from_str(&json).unwrap(); | ||
| test::black_box(restored); | ||
| }); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See if you can avoid generating many changes due to auto-reformatting. This distracts from the actual changes in the file.