I thought I’d share this function I wrote back in the days when I was helping with DayZ Mod. The original BIS function used by Rocket was grossly unoptimised while also heavily used in the mod. We had few proposals for improvement, mine happened to be the fastest. I think it is still used in DayZ Mod today.
Anyway, instead of copying and pasting the old code, I decided to improve it a bit more and make the use of some of the inbuilt BIS functions like a pro. So here it is:
By now you are probably wondering, how does this function compare to BIS official function – BIS_fnc_inString, which is supposed to do the same thing? I think I should mention that in ArmA 3 BIS_fnc_inString is not the same as the one in ArmA 2, it has been rewritten and possibly improved.
So I have constructed a devious test where the needle would be at the end of the haystack but also that haystack would have a lot of near matches. After some code performance testing here is the result:
My function is almost 4 times faster than official. As you can see from the function code, the speed of the function depends on the length of the haystack minus length of the needle. Because of that the function performance is predictable and reliable. Since I’m not BIS employee I don’t think there any chance for this function making it to ArmA 3, however if BIS peeps are reading, take it, I don’t want anything for it. No? Then maybe use it as a template to improve the official one?
But I tell you what, all this is a child’s play in comparison to what real men do when they need string search. I have done the same code performance test on RegEx extension I’ve made earlier (gotta start pushing that documentation out grrr).
Oh yeah! That is 76 times faster than my inString function and 290 times faster than the official one, LMAO!