Skip to content

Commit 617cd6a

Browse files
committed
clean up benchmark a bit
1 parent ff6c2d3 commit 617cd6a

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

benches/bench.rs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,6 @@ fn cl100k_base_benchmark(c: &mut Criterion) {
3232
));
3333
});
3434
});
35-
c.bench_function("cl100k_base_tiktoken-rs", |b| {
36-
b.iter(|| {
37-
black_box(y.encode_with_special_tokens(
38-
&t
39-
));
40-
});
41-
});
4235
c.bench_function("cl100k_base_50atatime", |b| {
4336
b.iter(|| {
4437
black_box(t.chars()
@@ -57,16 +50,32 @@ fn cl100k_base_benchmark(c: &mut Criterion) {
5750
.collect::<Vec<_>>());
5851
});
5952
});
60-
let y = x.encode(
53+
c.bench_function("tiktoken_rs::cl100k_base", |b| {
54+
b.iter(|| {
55+
black_box(y.encode_with_special_tokens(
56+
&t
57+
));
58+
});
59+
});
60+
let out = x.encode(
6161
&t,
6262
&SpecialTokenHandling {
6363
default: SpecialTokenAction::Special,
6464
..Default::default()
6565
}
6666
)
6767
.unwrap();
68-
println!("num tokens: {:?}", y.len());
68+
println!("num tokens: {:?}", out.len());
69+
let est = x.estimate_num_tokens_no_special_tokens_fast(&t, false);
70+
println!("estimated num tokens: {:?}", est);
6971
}
7072

71-
criterion_group!(benches, cl100k_base_benchmark);
72-
criterion_main!(benches);
73+
criterion_group!(
74+
name = benches;
75+
config = Criterion::default()
76+
.warm_up_time(std::time::Duration::from_secs(4))
77+
.measurement_time(std::time::Duration::from_secs(8))
78+
.sample_size(150);
79+
targets = cl100k_base_benchmark
80+
);
81+
criterion_main!(benches);

0 commit comments

Comments
 (0)