wikiparser/benches/id_parsing.rs
Evan Lloyd New-Schmidt 34bb9318d5 Refactor and rename title/qid wrappers
- Move Qid and Title to separate modules
- Reformat benchmark

Signed-off-by: Evan Lloyd New-Schmidt <evan@new-schmidt.com>
2023-08-10 09:37:58 -04:00

42 lines
859 B
Rust

#![feature(test)]
use std::{collections::HashSet, str::FromStr};
extern crate om_wikiparser;
extern crate test;
use om_wikiparser::wm::{Qid, Title};
const TITLE: &str = "https://en.wikipedia.org/wiki/Article_Title";
const QID: &str = "Q123456789";
#[bench]
fn parse_wikipedia(b: &mut test::Bencher) {
b.iter(|| {
Title::from_url(TITLE).unwrap();
});
}
#[bench]
fn hash_wikipedia(b: &mut test::Bencher) {
let title = Title::from_url(TITLE).unwrap();
let mut set = HashSet::new();
b.iter(|| {
set.insert(&title);
});
}
#[bench]
fn parse_wikidata(b: &mut test::Bencher) {
b.iter(|| {
Qid::from_str(QID).unwrap();
});
}
#[bench]
fn hash_wikidata(b: &mut test::Bencher) {
let qid = Qid::from_str(QID).unwrap();
let mut set = HashSet::new();
b.iter(|| {
set.insert(&qid);
});
}