Skip to content

Commit

Permalink
Add benches
Browse files Browse the repository at this point in the history
  • Loading branch information
afonso360 committed Apr 30, 2017
1 parent 8424983 commit 6a79d4d
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions benches/number.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright (c) the nom-lua contributors. All rights reserved.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. This file is also subject
* to the Linking exception provided in the LICENSE file that
* accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#![feature(test)]

extern crate test;
extern crate nom_lua;

use test::Bencher;
use nom_lua::number;

#[bench]
fn parse_hex_int(b: &mut Bencher) {
let ints: Vec<String> =
test::black_box((0..32)
.map(|i| format!("0x{:X}", i).to_string())
.collect());

b.iter(|| {
for i in ints.iter() {
number::parse_number(i.as_bytes());
}
});
}

#[bench]
fn parse_int(b: &mut Bencher) {
let ints: Vec<String> =
test::black_box((0..32)
.map(|i| format!("{}", i).to_string())
.collect());

b.iter(|| {
for i in ints.iter() {
number::parse_number(i.as_bytes());
}
});
}

#[bench]
fn parse_float(b: &mut Bencher) {
let ints: Vec<String> =
test::black_box((0..32)
.map(|i| format!("{}", i as f32).to_string())
.collect());

b.iter(|| {
for i in ints.iter() {
number::parse_number(i.as_bytes());
}
});
}

0 comments on commit 6a79d4d

Please sign in to comment.