aboutsummaryrefslogtreecommitdiff
path: root/vendor/once_cell/examples/regex.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2024-07-19 15:37:58 +0300
committerValentin Popov <valentin@popov.link>2024-07-19 15:37:58 +0300
commita990de90fe41456a23e58bd087d2f107d321f3a1 (patch)
tree15afc392522a9e85dc3332235e311b7d39352ea9 /vendor/once_cell/examples/regex.rs
parent3d48cd3f81164bbfc1a755dc1d4a9a02f98c8ddd (diff)
downloadfparkan-a990de90fe41456a23e58bd087d2f107d321f3a1.tar.xz
fparkan-a990de90fe41456a23e58bd087d2f107d321f3a1.zip
Deleted vendor folder
Diffstat (limited to 'vendor/once_cell/examples/regex.rs')
-rw-r--r--vendor/once_cell/examples/regex.rs49
1 files changed, 0 insertions, 49 deletions
diff --git a/vendor/once_cell/examples/regex.rs b/vendor/once_cell/examples/regex.rs
deleted file mode 100644
index 4c4c2ea..0000000
--- a/vendor/once_cell/examples/regex.rs
+++ /dev/null
@@ -1,49 +0,0 @@
-use std::{str::FromStr, time::Instant};
-
-use regex::Regex;
-
-macro_rules! regex {
- ($re:literal $(,)?) => {{
- static RE: once_cell::sync::OnceCell<regex::Regex> = once_cell::sync::OnceCell::new();
- RE.get_or_init(|| regex::Regex::new($re).unwrap())
- }};
-}
-
-fn slow() {
- let s = r##"13.28.24.13 - - [10/Mar/2016:19:29:25 +0100] "GET /etc/lib/pChart2/examples/index.php?Action=View&Script=../../../../cnf/db.php HTTP/1.1" 404 151 "-" "HTTP_Request2/2.2.1 (http://pear.php.net/package/http_request2) PHP/5.3.16""##;
-
- let mut total = 0;
- for _ in 0..1000 {
- let re = Regex::new(
- r##"^(\S+) (\S+) (\S+) \[([^]]+)\] "([^"]*)" (\d+) (\d+) "([^"]*)" "([^"]*)"$"##,
- )
- .unwrap();
- let size = usize::from_str(re.captures(s).unwrap().get(7).unwrap().as_str()).unwrap();
- total += size;
- }
- println!("{}", total);
-}
-
-fn fast() {
- let s = r##"13.28.24.13 - - [10/Mar/2016:19:29:25 +0100] "GET /etc/lib/pChart2/examples/index.php?Action=View&Script=../../../../cnf/db.php HTTP/1.1" 404 151 "-" "HTTP_Request2/2.2.1 (http://pear.php.net/package/http_request2) PHP/5.3.16""##;
-
- let mut total = 0;
- for _ in 0..1000 {
- let re: &Regex = regex!(
- r##"^(\S+) (\S+) (\S+) \[([^]]+)\] "([^"]*)" (\d+) (\d+) "([^"]*)" "([^"]*)"$"##,
- );
- let size = usize::from_str(re.captures(s).unwrap().get(7).unwrap().as_str()).unwrap();
- total += size;
- }
- println!("{}", total);
-}
-
-fn main() {
- let t = Instant::now();
- slow();
- println!("slow: {:?}", t.elapsed());
-
- let t = Instant::now();
- fast();
- println!("fast: {:?}", t.elapsed());
-}