URI parse based on nom composing parser library.
Provides simple parser that parses URI string into structure optimized for processing - Query is parsed to HashTable, path to Path etc.
Consider this code: ``` extern crate hyper; extern crate uri_parser;
use uriparser::parseuri; use std::time::{Duration, SystemTime};
use hyper::Uri; use std::str::FromStr;
fn durf64(d: Duration) -> f64 { d.assecs() as f64 + d.subsec_nanos() as f64 / 1e9 }
fn main() { let count = 1000000; let auri = "http://www.example.com/root/test?kulo=sak&kde=je&help=no&usi=yes#middle"; let start = SystemTime::now(); for _i in 0..count { let u = parseuri(auri).unwrap(); let d = u.query.unwrap(); let h=d.get("help").unwrap(); asserteq!(*h, "no"); } let dur = start.elapsed().unwrap(); println!("{} loops of my parseuri took {} secs", count, durf64(dur)); let start = SystemTime::now(); for i in 0..count { let u = Uri::fromstr(auri).unwrap(); let q = u.query().unwrap(); for qi in q.split("&") { let kv: Vec<_> = qi.split("=").collect(); if kv[0] == "help" { let h = kv[1]; asserteq!(h, "no"); } } } let dur = start.elapsed().unwrap(); println!("{} loops of hyper fromstr took {} secs", count, durf64(dur)); } ```
This library will perform better as query string is already in HashMap:
1000000 loops of my parse_uri took 0.900562534 secs
1000000 loops of hyper from_str took 1.136823832 secs