Add the first use of the rust benchmark tests.

This commit is contained in:
Tom Alexander 2023-10-16 15:50:08 -04:00
parent 547fc40dbe
commit 72b4cf8e71
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
2 changed files with 25 additions and 0 deletions

View File

@ -2,8 +2,11 @@
#![feature(trait_alias)] #![feature(trait_alias)]
#![feature(path_file_prefix)] #![feature(path_file_prefix)]
#![feature(is_sorted)] #![feature(is_sorted)]
#![feature(test)]
// TODO: #![warn(missing_docs)] // TODO: #![warn(missing_docs)]
extern crate test;
#[cfg(feature = "compare")] #[cfg(feature = "compare")]
pub mod compare; pub mod compare;

View File

@ -250,3 +250,25 @@ fn export_keyword<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>>
take_while1(|c: char| c.is_alphanumeric() || "-_".contains(c)), take_while1(|c: char| c.is_alphanumeric() || "-_".contains(c)),
)))(input) )))(input)
} }
#[cfg(test)]
mod tests {
use test::Bencher;
use super::*;
use crate::context::Context;
use crate::context::ContextElement;
use crate::context::GlobalSettings;
use crate::context::List;
use crate::parser::OrgSource;
#[bench]
fn bench_affiliated_keyword(b: &mut Bencher) {
let input = OrgSource::new("#+CAPTION[*foo*]: bar *baz*");
let global_settings = GlobalSettings::default();
let initial_context = ContextElement::document_context();
let initial_context = Context::new(&global_settings, List::new(&initial_context));
b.iter(|| assert!(affiliated_keyword(&initial_context, input).is_ok()));
}
}