Fix benchmarks
This commit is contained in:
parent
551e4f1f87
commit
4a802c1373
|
@ -1,93 +1,94 @@
|
|||
#[macro_use]
|
||||
extern crate criterion;
|
||||
extern crate rlua;
|
||||
#![cfg_attr(
|
||||
all(feature = "luajit", target_os = "macos", target_arch = "x86_64"),
|
||||
feature(link_args)
|
||||
)]
|
||||
|
||||
use criterion::Criterion;
|
||||
use rlua::prelude::*;
|
||||
#[cfg_attr(
|
||||
all(feature = "luajit", target_os = "macos", target_arch = "x86_64"),
|
||||
link_args = "-pagezero_size 10000 -image_base 100000000"
|
||||
)]
|
||||
extern "system" {}
|
||||
|
||||
use criterion::{criterion_group, criterion_main, BatchSize, Criterion};
|
||||
use mlua::prelude::*;
|
||||
|
||||
fn create_table(c: &mut Criterion) {
|
||||
c.bench_function("create table", |b| {
|
||||
b.iter_with_setup(
|
||||
b.iter_batched_ref(
|
||||
|| Lua::new(),
|
||||
|lua| -> Lua {
|
||||
|lua| {
|
||||
lua.create_table().unwrap();
|
||||
lua
|
||||
},
|
||||
BatchSize::SmallInput,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
fn create_array(c: &mut Criterion) {
|
||||
c.bench_function("create array 10", |b| {
|
||||
b.iter_with_setup(
|
||||
b.iter_batched_ref(
|
||||
|| Lua::new(),
|
||||
|lua| -> Lua {
|
||||
{
|
||||
let table = lua.create_table().unwrap();
|
||||
for i in 1..11 {
|
||||
table.set(i, i).unwrap();
|
||||
}
|
||||
|lua| {
|
||||
let table = lua.create_table().unwrap();
|
||||
for i in 1..11 {
|
||||
table.set(i, i).unwrap();
|
||||
}
|
||||
lua
|
||||
},
|
||||
BatchSize::SmallInput,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
fn create_string_table(c: &mut Criterion) {
|
||||
c.bench_function("create string table 10", |b| {
|
||||
b.iter_with_setup(
|
||||
b.iter_batched_ref(
|
||||
|| Lua::new(),
|
||||
|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| {
|
||||
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
|
||||
},
|
||||
BatchSize::SmallInput,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
fn call_add_function(c: &mut Criterion) {
|
||||
c.bench_function("call add function 3 10", |b| {
|
||||
b.iter_with_setup(
|
||||
b.iter_batched_ref(
|
||||
|| {
|
||||
let lua = Lua::new();
|
||||
let f = {
|
||||
let f: LuaFunction = lua
|
||||
.eval(
|
||||
.load(
|
||||
r#"
|
||||
function(a, b, c)
|
||||
return a + b + c
|
||||
end
|
||||
"#,
|
||||
None,
|
||||
function(a, b, c)
|
||||
return a + b + c
|
||||
end
|
||||
"#,
|
||||
)
|
||||
.eval()
|
||||
.unwrap();
|
||||
lua.create_registry_value(f).unwrap()
|
||||
};
|
||||
(lua, f)
|
||||
},
|
||||
|(lua, f)| -> Lua {
|
||||
{
|
||||
let add_function: LuaFunction = lua.registry_value(&f).unwrap();
|
||||
for i in 0..10 {
|
||||
let _result: i64 = add_function.call((i, i + 1, i + 2)).unwrap();
|
||||
}
|
||||
|(lua, f)| {
|
||||
let add_function: LuaFunction = lua.registry_value(f).unwrap();
|
||||
for i in 0..10 {
|
||||
let _result: i64 = add_function.call((i, i + 1, i + 2)).unwrap();
|
||||
}
|
||||
lua
|
||||
},
|
||||
BatchSize::SmallInput,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
fn call_add_callback(c: &mut Criterion) {
|
||||
c.bench_function("call callback add 2 10", |b| {
|
||||
b.iter_with_setup(
|
||||
b.iter_batched_ref(
|
||||
|| {
|
||||
let lua = Lua::new();
|
||||
let f = {
|
||||
|
@ -96,7 +97,7 @@ fn call_add_callback(c: &mut Criterion) {
|
|||
.unwrap();
|
||||
lua.globals().set("callback", c).unwrap();
|
||||
let f: LuaFunction = lua
|
||||
.eval(
|
||||
.load(
|
||||
r#"
|
||||
function()
|
||||
for i = 1,10 do
|
||||
|
@ -104,27 +105,25 @@ fn call_add_callback(c: &mut Criterion) {
|
|||
end
|
||||
end
|
||||
"#,
|
||||
None,
|
||||
)
|
||||
.eval()
|
||||
.unwrap();
|
||||
lua.create_registry_value(f).unwrap()
|
||||
};
|
||||
(lua, f)
|
||||
},
|
||||
|(lua, f)| -> Lua {
|
||||
{
|
||||
let entry_function: LuaFunction = lua.registry_value(&f).unwrap();
|
||||
entry_function.call::<_, ()>(()).unwrap();
|
||||
}
|
||||
lua
|
||||
|(lua, f)| {
|
||||
let entry_function: LuaFunction = lua.registry_value(f).unwrap();
|
||||
entry_function.call::<_, ()>(()).unwrap();
|
||||
},
|
||||
BatchSize::SmallInput,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
fn call_append_callback(c: &mut Criterion) {
|
||||
c.bench_function("call callback append 10", |b| {
|
||||
b.iter_with_setup(
|
||||
b.iter_batched_ref(
|
||||
|| {
|
||||
let lua = Lua::new();
|
||||
let f = {
|
||||
|
@ -135,7 +134,7 @@ fn call_append_callback(c: &mut Criterion) {
|
|||
.unwrap();
|
||||
lua.globals().set("callback", c).unwrap();
|
||||
let f: LuaFunction = lua
|
||||
.eval(
|
||||
.load(
|
||||
r#"
|
||||
function()
|
||||
for _ = 1,10 do
|
||||
|
@ -143,35 +142,33 @@ fn call_append_callback(c: &mut Criterion) {
|
|||
end
|
||||
end
|
||||
"#,
|
||||
None,
|
||||
)
|
||||
.eval()
|
||||
.unwrap();
|
||||
lua.create_registry_value(f).unwrap()
|
||||
};
|
||||
(lua, f)
|
||||
},
|
||||
|(lua, f)| -> Lua {
|
||||
{
|
||||
let entry_function: LuaFunction = lua.registry_value(&f).unwrap();
|
||||
entry_function.call::<_, ()>(()).unwrap();
|
||||
}
|
||||
lua
|
||||
|(lua, f)| {
|
||||
let entry_function: LuaFunction = lua.registry_value(f).unwrap();
|
||||
entry_function.call::<_, ()>(()).unwrap();
|
||||
},
|
||||
BatchSize::SmallInput,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
fn create_registry_values(c: &mut Criterion) {
|
||||
c.bench_function("create registry 10", |b| {
|
||||
b.iter_with_setup(
|
||||
b.iter_batched_ref(
|
||||
|| Lua::new(),
|
||||
|lua| -> Lua {
|
||||
|lua| {
|
||||
for _ in 0..10 {
|
||||
lua.create_registry_value(lua.pack(true).unwrap()).unwrap();
|
||||
}
|
||||
lua.expire_registry_values();
|
||||
lua
|
||||
},
|
||||
BatchSize::SmallInput,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
@ -181,17 +178,15 @@ fn create_userdata(c: &mut Criterion) {
|
|||
impl LuaUserData for UserData {}
|
||||
|
||||
c.bench_function("create userdata 10", |b| {
|
||||
b.iter_with_setup(
|
||||
b.iter_batched_ref(
|
||||
|| Lua::new(),
|
||||
|lua| -> Lua {
|
||||
{
|
||||
let table: LuaTable = lua.create_table().unwrap();
|
||||
for i in 1..11 {
|
||||
table.set(i, UserData(i)).unwrap();
|
||||
}
|
||||
|lua| {
|
||||
let table: LuaTable = lua.create_table().unwrap();
|
||||
for i in 1..11 {
|
||||
table.set(i, UserData(i)).unwrap();
|
||||
}
|
||||
lua
|
||||
},
|
||||
BatchSize::SmallInput,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
@ -209,7 +204,7 @@ criterion_group! {
|
|||
call_add_callback,
|
||||
call_append_callback,
|
||||
create_registry_values,
|
||||
create_userdata
|
||||
create_userdata,
|
||||
}
|
||||
|
||||
criterion_main!(benches);
|
||||
|
|
Loading…
Reference in New Issue