Inte Posted March 21, 2016 Posted March 21, 2016 I needed a function that would search an array for a specific value and return its index.Came up with this, INT Function iDDeFindStringIdx(STRING[] sArray, STRING sFind = "") INT iCount = sArray.Length INT i = 0 While (i < iCount) If (sArray[i] == sFind) RETURN i Else i += 1 EndIf EndWhile RETURN -1 EndFunction Would call it like so, iDDeFindStringIdx(sArray, sValue) But then I find that there is a Papyrus global function that does the same thing. sArray.Find(sValue) So, which one would be faster and less expensive?
spoonsinger Posted March 21, 2016 Posted March 21, 2016 Don't know. You would hope that the native one would be, (but it is Skyrim). Anyway hows about using the SKSE GetCurrentRealTime function for a test. (i.e. Get start time, call your function a few thousand times in a loop for the last value in the array, then get the end time, then calculate end time minus start time for the time it took and dump it to the console. Then repeat for the native function. )
Content Consumer Posted March 22, 2016 Posted March 22, 2016 Without having seen any of the actual papyrus code, I'd still guess that it works the same way. There are only a limited number of ways you can iterate through an array. But like spoonsinger said, it's not a bad idea to run a test like that. It'll confirm one way or another.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.