mirror of
https://github.com/Noratrieb/jsonformat.git
synced 2026-01-14 22:25:01 +01:00
binary cleanup
This commit is contained in:
parent
c5e63a743a
commit
35332a1b26
7 changed files with 59 additions and 31 deletions
|
|
@ -1,21 +1,26 @@
|
|||
use std::{fs, io};
|
||||
use std::{fs, io, path::PathBuf};
|
||||
|
||||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||
use jsonformat::{format, format_reader_writer, Indentation};
|
||||
|
||||
fn criterion_benchmark(c: &mut Criterion) {
|
||||
let file = include_str!("large-file.json");
|
||||
// using `include_str` makes the benches a lot less reliable for some reason???
|
||||
let file = PathBuf::from(file!())
|
||||
.parent()
|
||||
.unwrap()
|
||||
.join("large-file.json");
|
||||
let file = fs::read_to_string(file).unwrap();
|
||||
|
||||
c.bench_function("Format json default settings", |b| {
|
||||
b.iter(|| {
|
||||
let json = format(&file, Indentation::Default);
|
||||
let json = format(black_box(&file), Indentation::TwoSpace);
|
||||
black_box(json);
|
||||
})
|
||||
});
|
||||
|
||||
c.bench_function("Format json custom indentation", |b| {
|
||||
b.iter(|| {
|
||||
let json = format(&file, Indentation::Custom("123456"));
|
||||
let json = format(black_box(&file), Indentation::Custom("123456"));
|
||||
black_box(json);
|
||||
})
|
||||
});
|
||||
|
|
@ -24,7 +29,12 @@ fn criterion_benchmark(c: &mut Criterion) {
|
|||
b.iter(|| {
|
||||
let mut writer = Vec::with_capacity(file.len() * 2);
|
||||
|
||||
format_reader_writer(file.as_bytes(), &mut writer, Indentation::Default).unwrap();
|
||||
format_reader_writer(
|
||||
black_box(file.as_bytes()),
|
||||
&mut writer,
|
||||
Indentation::TwoSpace,
|
||||
)
|
||||
.unwrap();
|
||||
black_box(writer);
|
||||
})
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue