Talk:IsKeyPressed - Input: Difference between revisions

Jump to navigation Jump to search
→‎Boolean Switch: 'bIsKeyPressed = !bIsKeyPressed' vs. 'bIsKyePressed = Input.IsKeyPressed(iHotkey)'
imported>Cipscis
 
imported>JustinOther
(→‎Boolean Switch: 'bIsKeyPressed = !bIsKeyPressed' vs. 'bIsKyePressed = Input.IsKeyPressed(iHotkey)')
Line 5: Line 5:


-- [[User:Cipscis|Cipscis]] ([[User talk:Cipscis|talk]]) 17:48, 21 August 2012 (EDT)
-- [[User:Cipscis|Cipscis]] ([[User talk:Cipscis|talk]]) 17:48, 21 August 2012 (EDT)
Other than the [http://forums.bethsoft.com/topic/1381253-what-is-the-disadvantage-to-importing-functions-into-a-script/ few threads in the CK forum], there really hasn't been any such equivalent testing, not to the extent you had tested with  [http://forums.bethsoft.com/topic/987561-script-optimisation/page__p__14279570#entry14279570 FO3]/[http://forums.bethsoft.com/topic/1139867-script-optimisation/page__p__16678605__hl__optimisation__fromsearch__1#entry16678605 FNV]. Those threads were great, BTW :) I've been using a "quick 'n dirty" method to test snippets:
<source lang="papyrus">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</source>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 and, iterating both 10^4 times and...
<source lang="papyrus">bIsHotkeyPressed = IsKeyPressed(iHotkey)</source>
...spat out...
<source lang="html4strict">[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</source>
...while...
<source lang="papyrus">bIsHotkeyPressed = !bIsKeyPressed</source>...ran substantially faster sans the function call.
<source lang="html4strict">[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</source>
It ''appears'' the current example code is okay after all.
--[[User:JustinOther|JustinOther]]
Anonymous user

Navigation menu