Talk:IsKeyPressed - Input

Active discussions

Boolean SwitchEdit

I remember that, in previous games, it turned out that the equivalent to the example being used at the moment wasn't quite as efficient as the equivalent to this:

bIsHotkeyPressed = IsKeyPressed(iHotkey)

Of course, the difference was miniscule, but it was also measurable. I was just wondering if any equivalent testing has been done for Papyrus?

-- Cipscis (talk) 17:48, 21 August 2012 (EDT)

Other than the few threads in the CK forum, there really hasn't been any such equivalent testing, not to the extent you had tested with FO3/FNV. Those threads were great, BTW :) I've been using a "quick 'n dirty" method to test snippets:

Function SpeedTest01(Int aiIterations = 0, Float afStart = 0.0, Float afFinish = 0.0)
	Debug.Notification("Test 01 started...")
	afStart = Utility.GetCurrentRealTime()
	While aiIterations < 100000
		aiIterations += 1
		; Snippet to test
	EndWhile
	afFinish = Utility.GetCurrentRealTime()
	Debug.Trace("Start 01: " + afStart)
	Debug.Trace("Finish 01: " + afFinish)
	Debug.Trace("Time elapsed 01: " + (afFinish - afStart))
	Debug.Notification("Time elapsed 01: " + (afFinish - afStart))
	RegisterForUpdate(0.3)
EndFunction

I've got four of these set up to run when arrow keys are pressed (unregistering for update, of course), making it easy to run code variants and compare their speed/cost.

Just ran them both through the mill iterating both 10^4 times and...

bIsHotkeyPressed = IsKeyPressed(iHotkey)

...spat out...

[08/21/2012 - 11:11:28PM] Start 02: 53.123001
[08/21/2012 - 11:11:28PM] Finish 02: 178.561996
[08/21/2012 - 11:11:28PM] Time elapsed 02: 125.438995

...while...

bIsHotkeyPressed = !bIsHotkeyPressed

...ran substantially faster sans the function call.

[08/21/2012 - 11:09:18PM] Start 01: 48.098000
[08/21/2012 - 11:09:18PM] Finish 01: 48.161999
[08/21/2012 - 11:09:18PM] Time elapsed 01: 0.063999

It appears the current example code is okay after all.

--JustinOther

Fantastic, thanks. I'd expected the functionless code to be faster, but after being surprised by it in the past I thought it best to check.
-- Cipscis (talk) 03:38, 22 August 2012 (EDT)
Had it not been for your Script Optimisation threads, I'd have never thought to test, so thank you. Those graphs you'd made were like porn for scripters! Definitely got the gears spinning...
--JustinOther
Return to "IsKeyPressed - Input" page.