benchmarks: add baseline comparison benchmarks for regular i/o

This commit is contained in:
Kat Marchán 2019-10-17 22:24:24 -04:00
parent 03ff19709a
commit 398773547b
No known key found for this signature in database
GPG Key ID: AEB529C08A3C7E9E
1 changed files with 30 additions and 1 deletions

View File

@ -1,8 +1,35 @@
use async_std::task;
use async_std::{fs as afs, task};
use std::fs::{self, File};
use std::io::prelude::*;
use cacache;
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use tempfile;
fn baseline_read_sync(c: &mut Criterion) {
let tmp = tempfile::tempdir().unwrap();
let path = tmp.path().join("test_file");
let data = b"hello world";
let mut fd = File::create(&path).unwrap();
fd.write_all(data).unwrap();
drop(fd);
c.bench_function("baseline_read_sync", move |b| {
b.iter(|| fs::read(&path).unwrap())
});
}
fn baseline_read_async(c: &mut Criterion) {
let tmp = tempfile::tempdir().unwrap();
let path = tmp.path().join("test_file");
let data = b"hello world";
let mut fd = File::create(&path).unwrap();
fd.write_all(data).unwrap();
drop(fd);
c.bench_function("baseline_read_async", move |b| {
b.iter(|| task::block_on(afs::read(&path)))
});
}
fn get_data_hash_sync(c: &mut Criterion) {
let tmp = tempfile::tempdir().unwrap();
let cache = tmp.path().to_owned();
@ -74,6 +101,8 @@ fn get_data_hash_async_big_data(c: &mut Criterion) {
criterion_group!(
benches,
baseline_read_sync,
baseline_read_async,
get_data_hash_async,
get_data_hash_sync,
get_data_async,