Talk:IsKeyPressed - Input: Difference between revisions

Jump to navigation Jump to search
m
Convert source tags to syntaxhighlight
imported>JustinOther
No edit summary
m (Convert source tags to syntaxhighlight)
 
Line 1: Line 1:
== Boolean Switch ==
== Boolean Switch ==
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:
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:
<source lang="papyrus">bIsHotkeyPressed = IsKeyPressed(iHotkey)</source>
<syntaxhighlight lang="papyrus">bIsHotkeyPressed = IsKeyPressed(iHotkey)</syntaxhighlight>
Of course, the difference was miniscule, but it was also measurable. I was just wondering if any equivalent testing has been done for Papyrus?
Of course, the difference was miniscule, but it was also measurable. I was just wondering if any equivalent testing has been done for Papyrus?


Line 7: Line 7:


Other than the [http://forums.bethsoft.com/topic/1381253-what-is-the-disadvantage-to-importing-functions-into-a-script/ few] [http://forums.bethsoft.com/topic/1381253-what-is-the-disadvantage-to-importing-functions-into-a-script/ 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:
Other than the [http://forums.bethsoft.com/topic/1381253-what-is-the-disadvantage-to-importing-functions-into-a-script/ few] [http://forums.bethsoft.com/topic/1381253-what-is-the-disadvantage-to-importing-functions-into-a-script/ 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)
<syntaxhighlight lang="papyrus">Function SpeedTest01(Int aiIterations = 0, Float afStart = 0.0, Float afFinish = 0.0)
Debug.Notification("Test 01 started...")
Debug.Notification("Test 01 started...")
afStart = Utility.GetCurrentRealTime()
afStart = Utility.GetCurrentRealTime()
Line 20: Line 20:
Debug.Notification("Time elapsed 01: " + (afFinish - afStart))
Debug.Notification("Time elapsed 01: " + (afFinish - afStart))
RegisterForUpdate(0.3)
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.  
EndFunction</syntaxhighlight>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...
Just ran them both through the mill iterating both 10^4 times and...
<source lang="papyrus">bIsHotkeyPressed = IsKeyPressed(iHotkey)</source>
<syntaxhighlight lang="papyrus">bIsHotkeyPressed = IsKeyPressed(iHotkey)</syntaxhighlight>
...spat out...
...spat out...
<source lang="html4strict">[08/21/2012 - 11:11:28PM] Start 02: 53.123001
<syntaxhighlight 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] Finish 02: 178.561996
[08/21/2012 - 11:11:28PM] Time elapsed 02: 125.438995</source>
[08/21/2012 - 11:11:28PM] Time elapsed 02: 125.438995</syntaxhighlight>
...while...
...while...
<source lang="papyrus">bIsHotkeyPressed = !bIsHotkeyPressed</source>...ran substantially faster sans the function call.
<syntaxhighlight lang="papyrus">bIsHotkeyPressed = !bIsHotkeyPressed</syntaxhighlight>...ran substantially faster sans the function call.
<source lang="html4strict">[08/21/2012 - 11:09:18PM] Start 01: 48.098000
<syntaxhighlight 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] Finish 01: 48.161999
[08/21/2012 - 11:09:18PM] Time elapsed 01: 0.063999</source>
[08/21/2012 - 11:09:18PM] Time elapsed 01: 0.063999</syntaxhighlight>


It ''appears'' the current example code is okay after all.
It ''appears'' the current example code is okay after all.

Navigation menu