mirror of
https://github.com/IntQuant/noita_entangled_worlds.git
synced 2025-10-19 07:03:16 +00:00
Add a benchmark
This commit is contained in:
parent
2a09cbbfaa
commit
6102c30b2e
2 changed files with 41 additions and 5 deletions
|
@ -3,6 +3,7 @@ use std::{
|
|||
cell::{LazyCell, RefCell},
|
||||
ffi::{c_int, c_void},
|
||||
sync::LazyLock,
|
||||
time::Instant,
|
||||
};
|
||||
|
||||
use addr_grabber::{grab_addrs, grabbed_fns, grabbed_globals};
|
||||
|
@ -100,10 +101,22 @@ fn on_world_initialized(lua: LuaState) {
|
|||
}
|
||||
|
||||
fn test_fn(_lua: LuaState) -> eyre::Result<()> {
|
||||
let player = noita::api::raw::entity_get_closest_with_tag(0.0, 0.0, "player_unit".into())?;
|
||||
noita::api::raw::entity_set_transform(player, 0.0, 0.0, 0.0, 1.0, 1.0)?;
|
||||
let start = Instant::now();
|
||||
let iters = 10000;
|
||||
for _ in 0..iters {
|
||||
let player = noita::api::raw::entity_get_closest_with_tag(0.0, 0.0, "player_unit".into())?;
|
||||
noita::api::raw::entity_set_transform(player, 0.0, 0.0, 0.0, 1.0, 1.0)?;
|
||||
}
|
||||
let elapsed = start.elapsed();
|
||||
|
||||
// noita::api::raw::game_print("Test game print".into())?;
|
||||
noita::api::raw::game_print(
|
||||
format!(
|
||||
"Took {}us to test, {}ns per call",
|
||||
elapsed.as_micros(),
|
||||
elapsed.as_nanos() / iters
|
||||
)
|
||||
.into(),
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -33,7 +33,31 @@ function module.on_local_player_spawn()
|
|||
end
|
||||
end
|
||||
EntitySetTransform(GameGetWorldStateEntity(), 0, 0)
|
||||
|
||||
end
|
||||
|
||||
local function fw_button(label)
|
||||
return imgui.Button(label, imgui.GetWindowWidth() - 15, 20)
|
||||
end
|
||||
|
||||
local function test_fn_lua()
|
||||
local start = GameGetRealWorldTimeSinceStarted()
|
||||
for i=1,10000 do
|
||||
local player = EntityGetClosestWithTag(0, 0, "player_unit")
|
||||
EntitySetTransform(player, 0, 0, 0, 1, 1)
|
||||
end
|
||||
local elapsed = GameGetRealWorldTimeSinceStarted() - start
|
||||
GamePrint(elapsed*1000000)
|
||||
end
|
||||
|
||||
function module.on_draw_debug_window(imgui)
|
||||
if imgui.CollapsingHeader("ewext") then
|
||||
if fw_button("test_fn") then
|
||||
ewext.test_fn()
|
||||
end
|
||||
if fw_button("test_fn_lua") then
|
||||
test_fn_lua()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function module.on_world_update()
|
||||
|
@ -41,7 +65,6 @@ function module.on_world_update()
|
|||
oh_another_world_state(GameGetWorldStateEntity())
|
||||
initial_world_state_entity = GameGetWorldStateEntity()
|
||||
end
|
||||
ewext.test_fn()
|
||||
end
|
||||
|
||||
return module
|
Loading…
Add table
Add a link
Reference in a new issue