Jump to content

Which Function is Faster?


Recommended Posts

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
	     i += 1

Would call it like so,

 iDDeFindStringIdx(sArray, sValue) 

But then I find that there is a Papyrus global function that does the same thing. :-/


So, which one would be faster and less expensive?

Link to comment

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. )

Link to comment

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.

Link to comment


This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...