Use criterion for benchmarking, add some simple benchmarks
This commit is contained in:
parent
431f84012a
commit
964666e11b
11
Cargo.toml
11
Cargo.toml
|
@ -22,7 +22,7 @@ default = ["builtin-lua"]
|
|||
# * LUA_NUMBER as double
|
||||
# * LUA_EXTRASPACE is sizeof(void*)
|
||||
# * LUAI_MAXSTACK is 1000000
|
||||
builtin-lua = ["gcc"]
|
||||
builtin-lua = ["cc"]
|
||||
|
||||
[dependencies]
|
||||
libc = { version = "0.2" }
|
||||
|
@ -30,7 +30,12 @@ failure = { version = "0.1.1" }
|
|||
compiletest_rs = { version = "0.3", optional = true }
|
||||
|
||||
[build-dependencies]
|
||||
gcc = { version = "0.3.52", optional = true }
|
||||
cc = { version = "1.0", optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
rustyline = "1.0.0"
|
||||
rustyline = "1.0.0"
|
||||
criterion = "0.2.0"
|
||||
|
||||
[[bench]]
|
||||
name = "benchmark"
|
||||
harness = false
|
|
@ -0,0 +1,49 @@
|
|||
#[macro_use]
|
||||
extern crate criterion;
|
||||
extern crate rlua;
|
||||
|
||||
use criterion::Criterion;
|
||||
use rlua::prelude::*;
|
||||
|
||||
fn create_table(lua: Lua) -> Lua {
|
||||
{
|
||||
lua.create_table().unwrap();
|
||||
}
|
||||
lua
|
||||
}
|
||||
|
||||
fn create_array(lua: Lua) -> Lua {
|
||||
{
|
||||
let table = lua.create_table().unwrap();
|
||||
for i in 1..11 {
|
||||
table.set(i, i).unwrap();
|
||||
}
|
||||
}
|
||||
lua
|
||||
}
|
||||
|
||||
fn create_string_table(lua: Lua) -> Lua {
|
||||
{
|
||||
let table = lua.create_table().unwrap();
|
||||
for &s in &["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"] {
|
||||
let s = lua.create_string(s).unwrap();
|
||||
table.set(s.clone(), s).unwrap();
|
||||
}
|
||||
}
|
||||
lua
|
||||
}
|
||||
|
||||
fn criterion_benchmark(c: &mut Criterion) {
|
||||
c.bench_function("create_table", |b| {
|
||||
b.iter_with_setup(|| Lua::new(), create_table)
|
||||
});
|
||||
c.bench_function("create_array", |b| {
|
||||
b.iter_with_setup(|| Lua::new(), create_array)
|
||||
});
|
||||
c.bench_function("create_string_table", |b| {
|
||||
b.iter_with_setup(|| Lua::new(), create_string_table)
|
||||
});
|
||||
}
|
||||
|
||||
criterion_group!(benches, criterion_benchmark);
|
||||
criterion_main!(benches);
|
4
build.rs
4
build.rs
|
@ -1,5 +1,5 @@
|
|||
#[cfg(feature = "builtin-lua")]
|
||||
extern crate gcc;
|
||||
extern crate cc;
|
||||
|
||||
fn main() {
|
||||
#[cfg(feature = "builtin-lua")]
|
||||
|
@ -9,7 +9,7 @@ fn main() {
|
|||
let target_os = env::var("CARGO_CFG_TARGET_OS");
|
||||
let target_family = env::var("CARGO_CFG_TARGET_FAMILY");
|
||||
|
||||
let mut config = gcc::Build::new();
|
||||
let mut config = cc::Build::new();
|
||||
|
||||
if target_os == Ok("linux".to_string()) {
|
||||
config.define("LUA_USE_LINUX", None);
|
||||
|
|
Loading…
Reference in New Issue