File: conversion.rs

package info (click to toggle)
libchewing 0.11.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,584 kB
  • sloc: ansic: 7,148; perl: 291; python: 190; sh: 127; makefile: 44
file content (29 lines) | stat: -rw-r--r-- 684 bytes parent folder | download | duplicates (2)
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
#![feature(test)]

extern crate test;

use chewing::{
    conversion::{ChewingEngine, Composition, Symbol},
    dictionary::{Dictionary, TrieBuf},
    syl,
    zhuyin::Bopomofo::*,
};
use test::Bencher;

fn test_dictionary() -> impl Dictionary {
    TrieBuf::from([
        (vec![syl![H, A]], vec![("哈", 1)]),
        (vec![syl![H, A], syl![H, A]], vec![("哈哈", 1)]),
    ])
}

#[bench]
fn bench_conv(b: &mut Bencher) {
    let dict = test_dictionary();
    let engine = ChewingEngine::new();
    let mut composition = Composition::new();
    for _ in 0..40 {
        composition.push(Symbol::from(syl![H, A]));
    }
    b.iter(|| engine.convert(&dict, &composition).nth(1));
}