Template:Strfind quick

{{Documentation|content=

The Template:Strfind_quick can rapidly search for a substring within a long string of up to 500 characters maximum. Parameter 1 is the base string, and parameter 2 is the search string (lengths are calculated for the strings). Optional parameter lenstr=55 is the length to search within the base string (default: full length).


 * Usage: {{strfind quick|123456789x1234|x}} &rarr; {{strfind quick|123456789x1234|x}}
 * {{strfind quick|Veni vidi vici|di}} &rarr; {{strfind quick|Veni vidi vici|di}}
 * {{strfind quick|These...490 letters...endx.|endx}} &rarr; 496

For substrings beyond the 500-character limit, then the result will be "-1" as the search stops at 499+1 and ignores the remainder of a very long string. Parameter 1 could be over 1,000 characters long, but only the first 500 would be searched.

Performance considerations
This template exits the search at the first match, to reduce the use of template resources, such as post-expand include size. However, when used on strings nearing 500 characters, it uses extensive template resources, and very long strings can be searched only 4 times per page, running 0.7 seconds per search, and using nearly 500,000 bytes of argument space per search (limit: 2,048,000 bytes). Otherwise, for short strings, {strfind_quick} uses only a tiny fraction of the maximum, and could be used many times per page. For 15-character strings, it can run 25x times per second, versus only once per second for 500 long.

Due to the extensive computing resources needed, this template should be rewritten to invoke a Lua script module to run many thousands of times faster.

}}