Removed pair consumption from benchmark.
@@ -13,60 +13,15 @@ extern crate pest;
extern crate pest_grammars;
extern crate test;
-use std::collections::HashMap;
use std::fs::File;
use std::io::Read;
use test::Bencher;
use pest::Parser;
-use pest::Span;
-use pest::iterators::Pair;
use pest_grammars::json::*;
-enum Json<'i> {
- Null,
- Bool(bool),
- Number(f64),
- String(Span<'i>),
- Array(Vec<Json<'i>>),
- Object(HashMap<Span<'i>, Json<'i>>)
-}
-
-fn consume(pair: Pair<Rule>) -> Json {
- fn value(pair: Pair<Rule>) -> Json {
- let pair = pair.into_inner().next().unwrap();
-
- match pair.as_rule() {
- Rule::null => Json::Null,
- Rule::bool => match pair.as_str() {
- "false" => Json::Bool(false),
- "true" => Json::Bool(true),
- _ => unreachable!()
- },
- Rule::number => Json::Number(pair.as_str().parse().unwrap()),
- Rule::string => Json::String(pair.as_span()),
- Rule::array => Json::Array(pair.into_inner().map(value).collect()),
- Rule::object => {
- let pairs = pair.into_inner().map(|pos| {
- let mut pair = pos.into_inner();
-
- let key = pair.next().unwrap().as_span();
- let value = value(pair.next().unwrap());
-
- (key, value)
- });
-
- Json::Object(pairs.collect())
- }
- _ => unreachable!()
- }
- }
-
- value(pair)
-}
-
#[bench]
fn data(b: &mut Bencher) {
let mut file = File::open("benches/data.json").unwrap();
@@ -74,11 +29,5 @@ fn data(b: &mut Bencher) {
file.read_to_string(&mut data).unwrap();
- b.iter(|| {
- // consume(
- JsonParser::parse(Rule::json, &data).unwrap()
- // .next()
- // .unwrap()
- // )
- });
+ b.iter(|| JsonParser::parse(Rule::json, &data).unwrap());
}
