How does virus scanning work?
There are in fact tens of thousands of variants, not just hundreds. The scanner can narrow down the search by only looking in executable files and other known file types (such as Word .doc files that can contain macros.) In general it would be pointless to search things like .txt files because you can’t execute a text file, therefore it cannot contain a virus. Another thing to note is that while there may be tens of thousands of signatures to scan for, the algorithms for matching a given set of bytes against a list of signatures are very efficient. Pattern matching is a basic area of study of computer science (that has existed for decades) and there are many fast algorithms for doing this, and in practice the bottleneck is just reading the data from disk, not actually the scanning part. But any scanner that just used straight pattern matching against a list of signatures would be obsolete because viruses have contained self-modifying code ever since the very earliest scanners existed.