0: Initial.
[?]
9Zb2bmkejrNknawUtr3MKvVstZkVDR8x8ritfgZXKrky
Jan 20, 2022, 8:42 PM
XUQUBCZFS6PNY63QMQEVMF2KTGJWY7AINKIGC2FIG2RYWFL4OWFQCDependencies
- [2]
J7LQJCGQ
Change contents
- file addition: src[2.1]
- file addition: lib.rs[0.15]
use ropey::Rope;use std::{fmt, fmt::Write};#[derive(Clone, Debug, Default)]pub struct RopeBuilderWrapper(ropey::RopeBuilder);impl RopeBuilderWrapper {pub fn new() -> Self {Self(ropey::RopeBuilder::new())}pub fn append(&mut self, chunk: &str) {self.0.append(chunk);}pub fn finish(self) -> Rope {self.0.finish()}}impl Write for RopeBuilderWrapper {fn write_str(&mut self, s: &str) -> fmt::Result {self.append(s);Ok(())}}pub struct StringContainerA(pub Vec<String>);pub struct StringContainerB(pub Vec<String>);impl fmt::Display for StringContainerA {fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {let mut a = String::new();for b in &self.0 {a.push_str(&format!("{}", b))}write!(f, "{}", a)}}impl fmt::Display for StringContainerB {fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {let mut a = RopeBuilderWrapper::new();for b in &self.0 {write!(a, "{}", b)?}write!(f, "{}", a.finish())}} - file addition: examples[2.1]
- file addition: criterion.rs[0.1067]
extern crate criterion;use criterion::{criterion_group, criterion_main, AxisScale, BenchmarkId, Criterion, PlotConfiguration,SamplingMode,};use pprof::criterion::{Output, PProfProfiler};use rope_bench::{StringContainerA, StringContainerB};use std::time::Duration;fn benchmark_a(criterion: &mut Criterion) {let mut group = criterion.benchmark_group("Formatters");let test_cases: Vec<String> = ["q9w83nurapw9e8urn3v ejf 0394 jadsaaewr gt54 3r","039q84nc09r8ewru0f94aw948h5n-9q3849v","39-48mu5f-9834u-5um0u-09e8 r9-g8hj e4tv[we ","nj90 834ng0w98unrf pjsznd-9854n posaein -4598nsae ","9083 4[o0wi9me30948jan=09w4nj3498h aosindm f=0WNJG [ODIFNGH;X","09w458thm0wv9e4hytn0w45t09w834u0q9w348mcr0q9384","0r7830h84hct09843 0-q9384ht 0q98h408nqf0-483 nfq0-38q9w34e h-q034hr- q29h83 t05q3gbt","0-q984 3htfiefdn-w9e3- tq934q-eru n","09w 834ehnfidunv -0394 320pfuqn3-94 qnfoasidng kjbn =293"," fornq=934 nhfpowerdn [aogtbh943q gas;kdnq =0384hj f0H4G -=Q9438THG [O"].iter().map(|a| a.to_string()).collect();let test_case_a = StringContainerA(test_cases.clone());let test_case_b = StringContainerB(test_cases.clone());group.plot_config(PlotConfiguration::default().summary_scale(AxisScale::Logarithmic)).sampling_mode(SamplingMode::Linear);group.bench_with_input(BenchmarkId::new("StringContainerA", String::from("")),&test_cases,|bencher, _| bencher.iter(|| {format!("{}", test_case_a);}),);group.bench_with_input(BenchmarkId::new("StringContainerB", String::from("")),&test_cases,|bencher, _| bencher.iter(|| {format!("{}", test_case_b);}),);group.finish();}criterion_group! {name = benchmarks;config = Criterion::default().with_profiler(PProfProfiler::new(100, Output::Flamegraph(None))).sample_size(100).warm_up_time(Duration::new(3, 0)).measurement_time(Duration::new(5, 0)).significance_level(0.05).with_plots();targets = benchmark_a}criterion_main!(benchmarks); - file addition: bench[2.1]
#!/bin/shcargo run --example criterion --release --features="flamegraph criterion" -- --bench; - file addition: Cargo.toml[2.1]
[package]name = "rope_bench"version = "0.1.0"edition = "2021"# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html[features]flamegraph = ["inferno"][dependencies]criterion = { version = "0.3", optional = true }inferno = { version = "0.10", default-features = false, features = ["nameattr",], optional = true }pprof = { version = "0.5", features = ["criterion", "flamegraph"] }ropey = "1.3"[[example]]name = "criterion"required-features = ["flamegraph", "criterion"] - file addition: .ignore[2.1]
.git.DS_Store**/target/**/Cargo.lock