diff --git a/ewext/src/lib.rs b/ewext/src/lib.rs index cd8090ed..06785831 100644 --- a/ewext/src/lib.rs +++ b/ewext/src/lib.rs @@ -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(()) } diff --git a/quant.ew/files/system/ewext_init/ewext_init.lua b/quant.ew/files/system/ewext_init/ewext_init.lua index c743cf17..72d9c08f 100644 --- a/quant.ew/files/system/ewext_init/ewext_init.lua +++ b/quant.ew/files/system/ewext_init/ewext_init.lua @@ -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 \ No newline at end of file