1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//! 読み込みと組み上げの速さを測る
//!
//! 使い方:
//! cargo run --release --example bench
use std::time::Instant;
const DEFAULT_FONT: &str = "font/latinmodern-math.otf";
const SAMPLES: &[&str] = &[
"H-O-H",
"O=C=O",
"H_3C-CH_2-OH",
"H_3C-C(=[:90]O)-OH",
"*6(-=-=-=)",
"**6(------)",
"*6(--?[a]-(-[:0]-[:60]-[:120]-[:180]?[a])---)",
"H_3C-C(>[:90]OH)(<:[:-90]H)-CH_2-CH_3",
];
fn main() {
let data = std::fs::read(DEFAULT_FONT).expect("試験用のフォントを読めません");
let start = Instant::now();
let font = lina::load_font(data).expect("フォントを読み込めません");
let loading = start.elapsed();
// 一度走らせて、測る前に暖めておく
for source in SAMPLES {
lina::render_svg(source, &font).expect(source);
}
let rounds = 1000;
let start = Instant::now();
for _ in 0..rounds {
for source in SAMPLES {
lina::render_svg(source, &font).expect(source);
}
}
let total = start.elapsed();
let each = total.as_secs_f64() / (rounds * SAMPLES.len()) as f64;
println!("読み込み {:.1} ミリ秒", loading.as_secs_f64() * 1000.0);
println!("組み上げ {:.1} マイクロ秒(分子 1 つあたり)", each * 1_000_000.0);
println!("見本の数 {}", SAMPLES.len());
}