Skip to content

Commit

Permalink
Proper use of Black boxes
Browse files Browse the repository at this point in the history
  • Loading branch information
AuracleTech committed Feb 20, 2024
1 parent 5bf5a9e commit 2c947cc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
2 changes: 1 addition & 1 deletion benches/initialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const EMPTY_SOURCE: &str = "";

fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("initialization", |b| {
b.iter(|| Tokenizer::new(black_box(EMPTY_SOURCE), &DUOS_RUST))
b.iter(|| black_box(Tokenizer::new(EMPTY_SOURCE, &DUOS_RUST)))
});
}

Expand Down
20 changes: 8 additions & 12 deletions benches/tokenize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,24 @@ fn criterion_benchmark(c: &mut Criterion) {
}
}

let mut total = 0;

c.bench_function(
"Tokenize Yuumi vulkan game engine",
|b: &mut criterion::Bencher<'_>| {
b.iter(|| {
total = 0;

for (_, source) in files.iter() {
let mut tokenizer = Tokenizer::new(black_box(source), black_box(&DUOS_RUST));

let subtotal_tokens = match tokenizer.tokenize_all() {
Ok(tokens) => tokens.len(),
Err(err) => panic!("{}", err),
};

total += subtotal_tokens;
let mut tokenizer = Tokenizer::new(source, &DUOS_RUST);
let tokens = tokenizer.tokenize_all().unwrap();
black_box(tokens);
}
})
},
);

let mut total = 0;
for (_, source) in files.iter() {
let mut tokenizer = Tokenizer::new(source, &DUOS_RUST);
total += tokenizer.tokenize_all().unwrap().len();
}
println!("Amount of tokens created : {}", total);
}

Expand Down

0 comments on commit 2c947cc

Please sign in to comment.