-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathbench.rs
More file actions
55 lines (48 loc) · 1.29 KB
/
bench.rs
File metadata and controls
55 lines (48 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#![feature(test)]
extern crate test;
use anyhow::Error;
use random_access_memory::RandomAccessMemory;
use test::Bencher;
use hypercore::{Feed, Storage};
async fn create_feed(page_size: usize) -> Result<Feed, Error> {
let storage =
Storage::new(|_| Box::pin(async move { Ok(RandomAccessMemory::new(page_size)) })).await?;
Feed::with_storage(storage).await
}
#[bench]
fn create(b: &mut Bencher) {
b.iter(|| {
async_std::task::block_on(async {
create_feed(1024).await.unwrap();
});
});
}
#[bench]
fn write(b: &mut Bencher) {
async_std::task::block_on(async {
let mut feed = create_feed(1024).await.unwrap();
let data = Vec::from("hello");
b.iter(|| {
async_std::task::block_on(async {
feed.append(&data).await.unwrap();
});
});
});
}
#[bench]
fn read(b: &mut Bencher) {
async_std::task::block_on(async {
let mut feed = create_feed(1024).await.unwrap();
let data = Vec::from("hello");
for _ in 0..1000 {
feed.append(&data).await.unwrap();
}
let mut i = 0;
b.iter(|| {
async_std::task::block_on(async {
feed.get(i).await.unwrap();
i += 1;
});
});
});
}