in reply to efficient method of matching a string against a list of substrings?
This might be more efficiently done in C++.
EDIT: How efficient do you need to be? Searching a 100,000-character string for 100,000 10-character substrings took me 57 seconds -
To get noticeably more efficient than this, you really need a lower level language like C++.use strict; use warnings; my ($input, $str, @str, $t); $input .= chr(97 + int rand 26) for 1..100000; for (1..100000) { $str = ''; $str .= chr(97 + int rand 26) for 1..10; push @str, $str; } $t = time(); for (@str) { print "$_\n" if index($input, $str) != -1; } print time() - $t;
|
|---|