Skip to content

Commit

Permalink
fix benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
Geal committed Apr 17, 2019
1 parent b7b3015 commit 7377ef7
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 5 deletions.
20 changes: 18 additions & 2 deletions benches/ini.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,26 @@ extern crate jemallocator;
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;

use criterion::*;
use nom::character::streaming::{alphanumeric, multispace, space};

//use nom::character::streaming::{alphanumeric, multispace, space};

use nom::{
map_res, IResult,
sequence::delimited,
bytes::complete::take_while,
character::complete::{alphanumeric, multispace, space, char}
};
use std::str;
use std::collections::HashMap;

fn category(i: &[u8]) -> IResult<&[u8], &str> {
map_res(delimited(char('['), take_while(|c| c != b']'), char(']')), str::from_utf8)(i)
}

fn complete_byte_slice_to_str<'a>(s: &'a[u8]) -> Result<&'a str, str::Utf8Error> {
str::from_utf8(s)
}

/*
named!(
category<&str>,
map_res!(
Expand All @@ -24,6 +39,7 @@ named!(
str::from_utf8
)
);
*/

named!(key_value <&[u8],(&str,&str)>,
do_parse!(
Expand Down
18 changes: 16 additions & 2 deletions benches/ini_complete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ extern crate jemallocator;
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;

use criterion::*;
use nom::character::complete::{alphanumeric, multispace, space};

use nom::{
map_res, IResult,
sequence::delimited,
bytes::complete::take_while,
character::complete::{alphanumeric, multispace, space, char}
};
use std::str;
use std::collections::HashMap;

/*
named!(category<&[u8], &str>, map_res!(
delimited!(
char!('['),
Expand All @@ -25,6 +30,15 @@ named!(category<&[u8], &str>, map_res!(
fn complete_byte_slice_to_str<'a>(s: &'a [u8]) -> Result<&'a str, str::Utf8Error> {
str::from_utf8(s)
}
*/

fn category(i: &[u8]) -> IResult<&[u8], &str> {
map_res(delimited(char('['), take_while(|c| c != b']'), char(']')), str::from_utf8)(i)
}

fn complete_byte_slice_to_str<'a>(s: &'a[u8]) -> Result<&'a str, str::Utf8Error> {
str::from_utf8(s)
}

named!(key_value <&[u8],(&str,&str)>,
do_parse!(
Expand Down
19 changes: 18 additions & 1 deletion benches/ini_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ use criterion::*;
#[global_allocator]
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;

use nom::IResult;
use nom::{
IResult, map_res, opt,
bytes::complete::{take_while, is_a},
sequence::{delimited, terminated},
character::complete::{char, alphanumeric, space0 as space, not_line_ending}
};


use std::collections::HashMap;

Expand All @@ -33,15 +39,25 @@ fn is_line_ending_or_comment(chr: char) -> bool {
chr == ';' || chr == '\n'
}

/*
named!(alphanumeric<&str,&str>, take_while!(is_alphanumeric));
named!(not_line_ending<&str,&str>, is_not!("\r\n"));
named!(space<&str,&str>, take_while!(is_space));
named!(space_or_line_ending<&str,&str>, is_a!(" \r\n"));
*/
fn space_or_line_ending(i: &str) -> IResult<&str, &str> {
is_a(" \r\n")(i)
}

fn right_bracket(c: char) -> bool {
c == ']'
}

fn category(i: &str) -> IResult<&str, &str> {
terminated(delimited(char('['), take_while(|c| c != ']'), char(']')), opt(is_a(" \r\n")))(i)
}

/*
named!(category <&str, &str>,
do_parse!(
tag!("[") >>
Expand All @@ -51,6 +67,7 @@ named!(category <&str, &str>,
(name)
)
);
*/

named!(key_value <&str,(&str,&str)>,
do_parse!(
Expand Down

0 comments on commit 7377ef7

Please sign in to comment.