From: spiralofhope Date: 2009-09-01T15:20:36+09:00 Subject: Re: Best Practice for Multiline Regexps On Tue, 1 Sep 2009 14:55:08 +0900 Robert Klemme wrote: > > 1) Read file to String, match string against first pattern, read > > next file into String, match with same pattern... once I've gone > > through all the files with the first pattern, start over with the > > next pattern. > > That's the worst you can do. > > 2) Read file to String, match whole string against all 20 patterns, > > go to next file, match against 20 patterns... > > Most efficient of the simple approaches. Robert is right from a hard drive perspective. To understand why method 2 works well - just remember that when a file is read from your disk, it is cached. Your first solution would force the system to cache file 1, process it, then cache file 2 to process it.. through to caching file n and then back to file 1 again, cycling through each pattern you're searching for for every file. It would be horribly taxing on disk access. But if we imagine that all the files are on a ramdisk, then could the first method possibly be better? Something in the back of my mind says method 2 is still better. -- http://spiralofhope.com