mirror of
https://github.com/TxtDot/dalet-rs.git
synced 2024-12-24 01:23:45 +03:00
doc: update bench example
This commit is contained in:
parent
54c594d3f6
commit
dd597d278c
3 changed files with 171 additions and 52 deletions
129
Cargo.lock
generated
129
Cargo.lock
generated
|
@ -100,6 +100,17 @@ version = "1.3.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0"
|
||||
|
||||
[[package]]
|
||||
name = "bigdecimal"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a6773ddc0eafc0e509fb60e48dff7f450f8e674a0686ae8605e8d9901bd5eefa"
|
||||
dependencies = [
|
||||
"num-bigint",
|
||||
"num-integer",
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bincode"
|
||||
version = "1.3.3"
|
||||
|
@ -175,7 +186,7 @@ dependencies = [
|
|||
"heck",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"syn 2.0.72",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -207,6 +218,7 @@ dependencies = [
|
|||
"bincode",
|
||||
"chumsky",
|
||||
"clap",
|
||||
"dlhn",
|
||||
"enum-procs",
|
||||
"flate2",
|
||||
"num_enum",
|
||||
|
@ -216,6 +228,41 @@ dependencies = [
|
|||
"zstd",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "deranged"
|
||||
version = "0.3.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4"
|
||||
dependencies = [
|
||||
"powerfmt",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dlhn"
|
||||
version = "0.1.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "56f8c0fbf92cd49450565bc2231273fabc48bbbf0d152b5b32ee4ce13eed469e"
|
||||
dependencies = [
|
||||
"bigdecimal",
|
||||
"dlhn_derive",
|
||||
"num-bigint",
|
||||
"num-traits",
|
||||
"serde",
|
||||
"serde_bytes",
|
||||
"time",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dlhn_derive"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e579511d5845df93b92409782ce0e5cdbc10dd239f5aa4c9e53f229d6ac620c0"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "enum-procs"
|
||||
version = "0.3.0"
|
||||
|
@ -223,7 +270,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "e188616f4527e2cf6128e58622bb2fd16ebcfa37a200b2d16739c3ca227bf649"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"syn",
|
||||
"syn 2.0.72",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -304,6 +351,31 @@ dependencies = [
|
|||
"adler",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-bigint"
|
||||
version = "0.4.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9"
|
||||
dependencies = [
|
||||
"num-integer",
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-conv"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9"
|
||||
|
||||
[[package]]
|
||||
name = "num-integer"
|
||||
version = "0.1.46"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f"
|
||||
dependencies = [
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.19"
|
||||
|
@ -331,7 +403,7 @@ dependencies = [
|
|||
"proc-macro-crate",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"syn 2.0.72",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -352,6 +424,12 @@ version = "0.3.30"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec"
|
||||
|
||||
[[package]]
|
||||
name = "powerfmt"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-crate"
|
||||
version = "3.1.0"
|
||||
|
@ -436,6 +514,15 @@ dependencies = [
|
|||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_bytes"
|
||||
version = "0.11.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "387cc504cb06bb40a96c8e04e951fe01854cf6bc921053c954e4a606d9675c6a"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.204"
|
||||
|
@ -444,7 +531,7 @@ checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"syn 2.0.72",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -455,7 +542,7 @@ checksum = "6c64451ba24fc7a6a2d60fc75dd9c83c90903b19028d4eff35e88fc1e86564e9"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"syn 2.0.72",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -477,6 +564,17 @@ version = "0.11.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.109"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.72"
|
||||
|
@ -488,6 +586,25 @@ dependencies = [
|
|||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.3.36"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885"
|
||||
dependencies = [
|
||||
"deranged",
|
||||
"num-conv",
|
||||
"powerfmt",
|
||||
"serde",
|
||||
"time-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time-core"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3"
|
||||
|
||||
[[package]]
|
||||
name = "toml_datetime"
|
||||
version = "0.6.8"
|
||||
|
@ -656,7 +773,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"syn 2.0.72",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
@ -27,10 +27,10 @@ chumsky = { version = "=1.0.0-alpha.7", features = ["label"], optional = true }
|
|||
ariadne = { version = "0.4.1", optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
rmp-serde = { version = "1.3.0" }
|
||||
bincode = { version = "1.3.3" }
|
||||
rmp-serde = "1.3.0"
|
||||
bincode = "1.3.3"
|
||||
flate2 = "1.0"
|
||||
|
||||
dlhn = "0.1"
|
||||
|
||||
[features]
|
||||
default = ["types", "daletpack", "parsers", "daleth"]
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
use dalet::{
|
||||
daletl::DlPage,
|
||||
daletpack::*,
|
||||
typed::{Hl, TNullArg, Tag::*},
|
||||
};
|
||||
use flate2::Compression;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::io::Write;
|
||||
|
||||
#[macro_export]
|
||||
|
@ -11,24 +13,59 @@ macro_rules! iprint {
|
|||
let start = std::time::Instant::now();
|
||||
let result = $func;
|
||||
let elapsed = start.elapsed();
|
||||
println!("{} ({:#?}): {}", $name, elapsed, result.len());
|
||||
println!("{} ({:#?}): {} bytes", $name, elapsed, result.len());
|
||||
|
||||
result
|
||||
}};
|
||||
}
|
||||
|
||||
pub fn compress_deflate(data: &[u8]) -> std::io::Result<Vec<u8>> {
|
||||
#[macro_export]
|
||||
macro_rules! bench {
|
||||
($name:expr, $func:expr) => {{
|
||||
let res = iprint!($name, $func);
|
||||
iprint!(
|
||||
$name.to_owned() + " zstd",
|
||||
utils::compress_zstd(&res).unwrap()
|
||||
);
|
||||
iprint!($name.to_owned() + " zlib", compress_zlib(&res).unwrap());
|
||||
iprint!(
|
||||
$name.to_owned() + " deflate",
|
||||
compress_deflate(&res).unwrap()
|
||||
);
|
||||
|
||||
println!();
|
||||
|
||||
res
|
||||
}};
|
||||
}
|
||||
|
||||
fn compress_deflate(data: &[u8]) -> std::io::Result<Vec<u8>> {
|
||||
let mut c = flate2::write::DeflateEncoder::new(Vec::new(), Compression::default());
|
||||
c.write_all(data)?;
|
||||
c.finish()
|
||||
}
|
||||
|
||||
pub fn compress_zlib(data: &[u8]) -> std::io::Result<Vec<u8>> {
|
||||
fn compress_zlib(data: &[u8]) -> std::io::Result<Vec<u8>> {
|
||||
let mut c = flate2::write::ZlibEncoder::new(Vec::new(), Compression::default());
|
||||
c.write_all(data)?;
|
||||
c.finish()
|
||||
}
|
||||
|
||||
fn dlhn_serialize(page: &DlPage) -> Vec<u8> {
|
||||
let mut output = Vec::new();
|
||||
let mut serializer = dlhn::Serializer::new(&mut output);
|
||||
page.serialize(&mut serializer).unwrap();
|
||||
|
||||
output
|
||||
}
|
||||
|
||||
fn dlhn_deserialize(output: &Vec<u8>) -> DlPage {
|
||||
let mut reader = output.as_slice();
|
||||
let mut deserializer = dlhn::Deserializer::new(&mut reader);
|
||||
|
||||
DlPage::deserialize(&mut deserializer).unwrap()
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let page = vec![
|
||||
H("Heading 1".into(), Hl::One),
|
||||
|
@ -78,44 +115,9 @@ fn main() {
|
|||
|
||||
let dalet_page = page.into();
|
||||
|
||||
let markdown = iprint!("Markdown", include_str!("./bench.md").as_bytes().to_vec());
|
||||
let daletpack = iprint!("Daletpack", encode_no_compress(&dalet_page).unwrap());
|
||||
let messagepack = iprint!("Messagepack", rmp_serde::to_vec(&dalet_page).unwrap());
|
||||
let bincode = iprint!("Bincode", bincode::serialize(&dalet_page).unwrap());
|
||||
|
||||
println!();
|
||||
|
||||
iprint!("Markdown zstd", utils::compress_zstd(&markdown).unwrap());
|
||||
let daletpack = iprint!("Daletpack zstd", utils::compress_zstd(&daletpack).unwrap());
|
||||
iprint!(
|
||||
"Messagepack zstd",
|
||||
utils::compress_zstd(&messagepack).unwrap()
|
||||
);
|
||||
iprint!("Bincode zstd", utils::compress_zstd(&bincode).unwrap());
|
||||
|
||||
println!();
|
||||
|
||||
iprint!("Markdown Zlib", compress_zlib(&markdown).unwrap());
|
||||
iprint!("Daletpack Zlib", compress_zlib(&daletpack).unwrap());
|
||||
iprint!("Messagepack Zlib", compress_zlib(&messagepack).unwrap());
|
||||
iprint!("Bincode Zlib", compress_zlib(&bincode).unwrap());
|
||||
|
||||
println!();
|
||||
|
||||
iprint!("Markdown deflate", compress_deflate(&markdown).unwrap());
|
||||
iprint!("Daletpack deflate", compress_deflate(&daletpack).unwrap());
|
||||
iprint!(
|
||||
"Messagepack deflate",
|
||||
compress_deflate(&messagepack).unwrap()
|
||||
);
|
||||
iprint!("Bincode deflate", compress_deflate(&bincode).unwrap());
|
||||
|
||||
println!();
|
||||
|
||||
let decoded = iprint!(
|
||||
"Daletpack decode",
|
||||
Decoder::new(&daletpack).unwrap().decode().unwrap().data
|
||||
);
|
||||
|
||||
println!("{:#?}", decoded);
|
||||
bench!("Markdown", include_str!("./bench.md").as_bytes().to_vec());
|
||||
bench!("Daletpack", encode_no_compress(&dalet_page).unwrap());
|
||||
bench!("Dlhn", dlhn_serialize(&dalet_page));
|
||||
bench!("Messagepack", rmp_serde::to_vec(&dalet_page).unwrap());
|
||||
bench!("Bincode", bincode::serialize(&dalet_page).unwrap());
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue