1. Lua/JS R* Platform Lua ``` function benchmark(fn, handle) local start = GetNetworkTimeAccurate() for x = 0, 10000000 do fn(handle) end return GetNetworkTimeAccurate() - start end function do_single_func_bench(name, fn, handle) local test_time = benchmark(fn, handle); TriggerEvent('chat:addMessage', { color = { 255, 0, 0}, multiline = true, args = { '' .. name .. ' (Lua): ' .. (test_time) .. ' ms !!' } }) end function do_mixed_bench(handle) local start_time = GetNetworkTimeAccurate() local st = IsPedShooting local inj = IsPedAimingFromCover local ir = IsPedReloading local sa = SetPedArmour local ga = GetPedArmour for x = 0, 1000000 - 1 do st(handle) -- Check if ped is shooting inj(handle) -- Check if ped is aiming from cover ir(handle) -- Check if ped is reloading sa(handle, 100) -- Set ped armour to 100 ga(handle) -- Get ped armour end local end_time = GetNetworkTimeAccurate() return end_time - start_time end RegisterCommand("bench_lua", function(source, args, rawCommand) local localPed = PlayerPedId(); // Out of benchmark iterations do_single_func_bench('IsPedShooting', IsPedShooting, localPed); do_single_func_bench('GetEntityCoords', GetEntityCoords, localPed); do_single_func_bench('IsEntityAttached', IsEntityAttached, localPed); do_single_func_bench('GetEntityHealth', GetEntityHealth, localPed); end, false) RegisterCommand("mixed_bench_lua", function(source, args, rawCommand) local localPed = PlayerPedId(); // Out of benchmark iterations local test_time = do_mixed_bench(localPed) TriggerEvent('chat:addMessage', { color = { 255, 0, 0}, multiline = true, args = { 'Mixed (Lua): ' .. (test_time) .. ' ms !!' } }) end, false) ``` R* Platform JS: ``` function benchmark(fn, handle) { const start = Date.now(); for (let x = 0; x != 10_000_000; ++x) fn(handle); const end_time = Date.now(); return end_time - start; } function do_single_func_bench(name, fn, handle) { const time = benchmark(fn, handle); emit('chat:addMessage', { color: [255, 0, 0], args: ['', `${name} (JS): ${time} ms`] }); } const st = IsPedShooting; const inj = IsPedAimingFromCover; const ir = IsPedReloading; const sa = SetPedArmour; const ga = GetPedArmour; function do_mixed_bench(handle, startTime) { for (let x = 0; x != 1_000_000; ++x) { st(handle); // Check if ped is shooting inj(handle); // Check if ped is aiming from cover ir(handle); // Check if ped is reloading sa(handle, 100); // Set ped armour to 100 ga(handle); // Get ped armour } const end_time = Date.now(); return end_time - startTime; } // To avoid "deadloop" detection const Delay = (ms) => new Promise(res => setTimeout(res, ms)); RegisterCommand('bench_js', async (source) => { const localPed = PlayerPedId(); do_single_func_bench('IsPedShooting', IsPedShooting, localPed); await Delay(1000); do_single_func_bench('GetEntityCoords', GetEntityCoords, localPed); await Delay(1000); do_single_func_bench('IsEntityAttached', IsEntityAttached, localPed); await Delay(1000); do_single_func_bench('GetEntityHealth', GetEntityHealth, localPed); await Delay(1000); }, false); RegisterCommand('mixed_bench_js', async (source) => { const localPed = PlayerPedId(); // Out of benchmark iterations const time = do_mixed_bench(localPed, Date.now()); emit('chat:addMessage', { color: [255, 0, 0], args: ['', `Mixed bench (JS): ${time} ms`] }); }, false); ``` RAGE Multiplayer JS: ``` function benchmark(fn, handle, ...extra_arg) { const start = Date.now(); for (let x = 0; x != 10_000_000; ++x) fn(handle, ...extra_arg); const end_time = Date.now(); return end_time - start; } function do_single_func_bench(name, fn, handle, ...extra_arg) { const time = benchmark(fn, handle, ...extra_arg); mp.gui.chat.push(`${name} (JS): ${time} ms`); } const { isShooting, isAimingFromCover, isReloading, setArmour, getArmour } = mp.game.ped; function do_mixed_bench(handle, startTime) { for (let x = 0; x != 1_000_000; ++x) { isShooting(handle); isAimingFromCover(handle); isReloading(handle); setArmour(handle, 100); getArmour(handle); } const end_time = Date.now(); return end_time - startTime; } mp.events.add("playerCommand", (command) => { if (command == 'bench') { const localPed = mp.players.local.handle; // Out of benchmark iterations do_single_func_bench('mp.game.ped.isShooting', mp.game.ped.isShooting, localPed); do_single_func_bench('mp.game.entity.getCoords', mp.game.entity.getCoords, localPed, true); do_single_func_bench('mp.game.entity.isAttached', mp.game.entity.isAttached, localPed); do_single_func_bench('mp.game.entity.getHealth', mp.game.entity.getHealth, localPed); } else if (command == 'mixed_bench') { const localPed = mp.players.local.handle; // Out of benchmark iterations const time = do_mixed_bench(localPed, Date.now()); mp.gui.chat.push(`Mixed bench: ${time}ms`); } }); ``` 2. C++/JS C++: ``` void ScriptInit() { while (true) { auto start = std::chrono::high_resolution_clock::now(); for (int i = 0; i < 1000000; i++) { int localPed = PLAYER::PLAYER_PED_ID(); int currentVehicle = PED::GET_VEHICLE_PED_IS_IN(localPed, false); Vector3 currentVehiclePos = ENTITY::GET_ENTITY_COORDS(currentVehicle, true); } auto end = std::chrono::high_resolution_clock::now(); char resultString[24]; sprintf_s(resultString, "SHV 1m: %lld ms", std::chrono::duration_cast(end - start).count()); Notify(resultString); WAIT(0); } } ``` RAGE Multiplayer JS: ``` const ITER = 1_000_000; mp.events.add("render", () => { let now = Date.now(); for (let i = 0; i < ITER; i++) { const localPed = mp.game.player.pedId(); const currentVehicle = mp.game.ped.getVehicleIsIn(localPed, false); const currentVehiclePos = mp.game.entity.getCoords(currentVehicle, true); } mp.gui.chat.push(`JS 1m: ${Date.now() - now}ms`); }); ```