Browse Source

Benchmarks

jD91mZM2 6 năm trước cách đây
mục cha
commit
9efe1bdd72
4 tập tin đã thay đổi với 17 bổ sung2 xóa
  1. 1 1
      Cargo.toml
  2. 0 0
      src/bench.rs
  3. 2 1
      src/lib.rs
  4. 14 0
      src/matcher.rs

+ 1 - 1
Cargo.toml

@@ -6,5 +6,5 @@ authors = ["jD91mZM2 <me@krake.one>"]
 [dependencies]
 
 [features]
-debug = []
+bench = []
 no_std = []

+ 0 - 0
src/bench.rs


+ 2 - 1
src/lib.rs

@@ -1,5 +1,6 @@
-#![cfg_attr(feature = "no_std", no_std)]
+#![cfg_attr(feature = "bench", feature(test))]
 #![cfg_attr(feature = "no_std", feature(alloc))]
+#![cfg_attr(feature = "no_std", no_std)]
 #![feature(nll)]
 
 #[cfg(feature = "no_std")]

+ 14 - 0
src/matcher.rs

@@ -361,6 +361,12 @@ pub struct PosixRegexResult {
 
 #[cfg(test)]
 mod tests {
+    #[cfg(feature = "bench")]
+    extern crate test;
+
+    #[cfg(feature = "bench")]
+    use self::test::Bencher;
+
     use super::*;
     use ::PosixRegexBuilder;
 
@@ -498,4 +504,12 @@ mod tests {
         assert!(matches_exact(r"\(a\|b\|c\)\{4\}d", "ababd").is_some());
         assert!(matches_exact(r"\(a\|b\|c\)\{4\}d", "abad").is_none());
     }
+
+    #[cfg(feature = "bench")]
+    #[bench]
+    fn speeeeed(b: &mut Bencher) {
+        b.iter(|| {
+            assert!(matches_exact(r"\(\(a*\|b\|c\) test\|yee\)", "aaaaa test").is_some());
+        })
+    }
 }