File: benchmark.rs

package info (click to toggle)
rust-parse-zoneinfo 0.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 352 kB
  • sloc: makefile: 4
file content (36 lines) | stat: -rw-r--r-- 1,264 bytes parent folder | download
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
extern crate parse_zoneinfo;

use parse_zoneinfo::line::{Line, LineParser};
use parse_zoneinfo::table::TableBuilder;

// This function is needed until zoneinfo_parse handles comments correctly.
// Technically a '#' symbol could occur between double quotes and should be
// ignored in this case, however this never happens in the tz database as it
// stands.
fn strip_comments(mut line: String) -> String {
    line.find('#').map(|pos| line.truncate(pos));
    line
}

fn main() {
    let lines = std::fs::read_to_string("examples/asia")
        .unwrap()
        .lines()
        .map(|line| strip_comments(line.to_string()))
        .collect::<Vec<_>>();

    for _ in 0..100 {
        let parser = LineParser::new();
        let mut builder = TableBuilder::new();
        for line in &lines {
            match parser.parse_str(&line).unwrap() {
                Line::Zone(zone) => builder.add_zone_line(zone).unwrap(),
                Line::Continuation(cont) => builder.add_continuation_line(cont).unwrap(),
                Line::Rule(rule) => builder.add_rule_line(rule).unwrap(),
                Line::Link(link) => builder.add_link_line(link).unwrap(),
                Line::Space => {}
            }
        }
        let _table = builder.build();
    }
}