Skip to content

Commit

Permalink
improve rust bench to exclude drop time
Browse files Browse the repository at this point in the history
  • Loading branch information
Daulet Zhanguzin committed Jul 10, 2024
1 parent 14835c0 commit fce4681
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fmt.Println(tk.Decode([]uint32{2829, 4419, 14523, 2058, 1996, 13971, 3899}, true

## Benchmarks

Decoding overhead (due to CGO) is between negligible and 9% depending on the benchmark.
Decoding overhead (due to CGO and extra allocations) is between 2% to 9% depending on the benchmark.

```bash
go test . -bench=. -benchmem -benchtime=10s
Expand Down
7 changes: 5 additions & 2 deletions benches/decode_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ fn bench_decode_n_tokens(c: &mut Criterion) {
let tokens: Vec<u32> = (0..iters).map(|_| rng.gen_range(0..max_token_id) as u32).collect();

let start = Instant::now();
decode(&tokenizer, black_box(&tokens), black_box(true));
start.elapsed()
let result = decode(&tokenizer, black_box(&tokens), black_box(true));
let duration = start.elapsed();
// we do this to exclude drop time for the result
_ = result;
duration
})}
);
}
Expand Down
19 changes: 10 additions & 9 deletions test/benchmark/rust_results.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
run with `cargo bench`

ecode_n_times time: [3.9812 µs 3.9874 µs 3.9939 µs]
change: [-0.4103% -0.1338% +0.1275%] (p = 0.33 > 0.05)
No change in performance detected.
Found 7 outliers among 100 measurements (7.00%)
7 (7.00%) high mild
decode_n_times time: [3.9349 µs 3.9588 µs 3.9846 µs]
change: [-1.6315% -1.2605% -0.8858%] (p = 0.00 < 0.05)
Change within noise threshold.
Found 10 outliers among 100 measurements (10.00%)
6 (6.00%) high mild
4 (4.00%) high severe

decode_n_tokens time: [651.72 ns 661.73 ns 675.78 ns]
change: [+0.3504% +2.0016% +3.5507%] (p = 0.01 < 0.05)
decode_n_tokens time: [628.40 ns 630.04 ns 632.03 ns]
change: [-3.6926% -2.1495% -0.5598%] (p = 0.01 < 0.05)
Change within noise threshold.
Found 7 outliers among 100 measurements (7.00%)
Found 4 outliers among 100 measurements (4.00%)
2 (2.00%) high mild
5 (5.00%) high severe
2 (2.00%) high severe

0 comments on commit fce4681

Please sign in to comment.