Debian Codegraph @

benches/build_large_table.rs

raw symbols SCIP
1 use comfy_table::{presets::UTF8_FULL, *};
2 use criterion::{Criterion, criterion_group, criterion_main};
3 use rand::{Rng, distr::Alphanumeric};
4
5 /// Create a dynamic 10x500 Table with width 300 and unevenly distributed content.
6 /// There are no constraint, the content simply has to be formatted to fit as good as possible into
7 /// the given space.
8 fn build_huge_table() {
9 let mut table = Table::new();
10 table
11 .load_preset(UTF8_FULL)
12 .set_content_arrangement(ContentArrangement::DynamicFullWidth)
13 .set_width(300)
14 .set_header(vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
15
16 let mut rng = rand::rng();
17 for _ in 0..500 {
18 let mut row = Vec::new();
19 for _ in 0..10 {
20 let string_length = rng.random_range(2..100);
21 let random_string: String = (&mut rng)
22 .sample_iter(&Alphanumeric)
23 .take(string_length)
24 .map(char::from)
25 .collect();
26 row.push(random_string);
27 }
28 table.add_row(row);
29 }
30
31 // Build the table.
32 let _ = table.lines();
33 }
34
35 pub fn build_tables(crit: &mut Criterion) {
36 crit.bench_function("Huge table", |b| b.iter(build_huge_table));
37 }
38
39 criterion_group!(benches, build_tables);
40 criterion_main!(benches);