Skip to content

Commit

Permalink
write bench exteneded
Browse files Browse the repository at this point in the history
  • Loading branch information
tower120 committed Sep 14, 2021
1 parent 8dd62c2 commit 3c7d8fe
Showing 1 changed file with 40 additions and 10 deletions.
50 changes: 40 additions & 10 deletions benches/write_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ use std::time::{Duration, Instant};
use std::collections::VecDeque;
use rc_event_queue::event_queue::EventQueue;

const queue_size : usize = 100000;
const QUEUE_SIZE: usize = 100000;


fn bench_event_extend_session(iters: u64, session_len: usize) -> Duration{
let mut total = Duration::ZERO;
let sessions_count = queue_size / session_len;
let sessions_count = QUEUE_SIZE / session_len;
for _ in 0..iters {
let event = EventQueue::<usize, 512, false>::new();
let start = Instant::now();
Expand All @@ -31,7 +31,7 @@ fn bench_event_extend(iters: u64) -> Duration{
let event = EventQueue::<usize, 512, false>::new();
let start = Instant::now();

event.extend(black_box(0..queue_size));
event.extend(black_box(0..QUEUE_SIZE));

total += start.elapsed();
}
Expand All @@ -44,7 +44,7 @@ fn bench_event_push(iters: u64) -> Duration{
let event = EventQueue::<usize, 512, false>::new();
let start = Instant::now();

for i in 0..queue_size{
for i in 0..QUEUE_SIZE {
event.push(black_box(i));
}

Expand All @@ -53,13 +53,13 @@ fn bench_event_push(iters: u64) -> Duration{
total
}

fn bench_vector_whole(iters: u64) -> Duration{
fn bench_vector_push(iters: u64) -> Duration{
let mut total = Duration::ZERO;
for _ in 0..iters {
let mut vec = Vec::new();
let start = Instant::now();

for i in 0..queue_size{
for i in 0..QUEUE_SIZE {
vec.push(black_box(i));
}

Expand All @@ -68,13 +68,27 @@ fn bench_vector_whole(iters: u64) -> Duration{
total
}

fn bench_deque_whole(iters: u64) -> Duration{
fn bench_vector_extend(iters: u64) -> Duration{
let mut total = Duration::ZERO;
for _ in 0..iters {
let mut vec = Vec::new();
let start = Instant::now();

vec.extend(black_box(0..QUEUE_SIZE));

total += start.elapsed();
}
total
}


fn bench_deque_push(iters: u64) -> Duration{
let mut total = Duration::ZERO;
for _ in 0..iters {
let mut vec = VecDeque::new();
let start = Instant::now();

for i in 0..queue_size{
for i in 0..QUEUE_SIZE {
vec.push_back(black_box(i));
}

Expand All @@ -83,6 +97,20 @@ fn bench_deque_whole(iters: u64) -> Duration{
total
}

fn bench_deque_extend(iters: u64) -> Duration{
let mut total = Duration::ZERO;
for _ in 0..iters {
let mut vec = VecDeque::new();
let start = Instant::now();

vec.extend(black_box(0..QUEUE_SIZE));

total += start.elapsed();
}
total
}


pub fn write_event_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("Write");
for session_size in [1, 4, 8, 16, 32, 128, 512]{
Expand All @@ -93,8 +121,10 @@ pub fn write_event_benchmark(c: &mut Criterion) {
}
group.bench_function("EventQueue::push", |b|b.iter_custom(|iters| bench_event_push(iters)));
group.bench_function("EventQueue::extend", |b|b.iter_custom(|iters| bench_event_extend(iters)));
group.bench_function("Vec", |b|b.iter_custom(|iters| bench_vector_whole(iters)));
group.bench_function("Deque", |b|b.iter_custom(|iters| bench_deque_whole(iters)));
group.bench_function("Vec::push", |b|b.iter_custom(|iters| bench_vector_push(iters)));
group.bench_function("Vec::extend", |b|b.iter_custom(|iters| bench_vector_extend(iters)));
group.bench_function("Deque::push", |b|b.iter_custom(|iters| bench_deque_push(iters)));
group.bench_function("Deque::extend", |b|b.iter_custom(|iters| bench_deque_extend(iters)));
}

criterion_group!(benches, write_event_benchmark);
Expand Down

0 comments on commit 3c7d8fe

Please sign in to comment.