>CD c:\users\pagan\documents\test >fname = "war and peace.txt" > >SET SAFETY OFF > >nStart = SECONDS() >LOCAL t1, t2, x, i >LOCAL ARRAY aStrings[5] >x= FILETOSTR(fname) >aStrings[1]= "Russia" && 775 occurences >aStrings[2]= "Anna" && 293 occurences >aStrings[3]= "Czar" && 4 occurences >aStrings[4]= "windows" && 23 occurences >aStrings[5]= "Pentium" && 0 occurences > >*x= FILETOSTR("WarAndPeace.TXT") && 3.2 mb in size >FOR i = 1 TO ALEN( aStrings) > t1= SECONDS() >OCCURS(aStrings[i],x) > t2= SECONDS() >[OCCURS( "]+aStrings[i]+[", x)], t2-t1, "seconds" && 0.401 seconds avg >ENDFOR > >>
> class Program > { > static void Main(string[] args) > { > Stopwatch stopwatch = new Stopwatch(); > > > string fname = @"C:\Users\Pagan\Documents\test\war and peace.txt"; > string foo = File.ReadAllText(fname); > > countem(stopwatch, foo, "Russia"); > countem(stopwatch, foo, "Anna"); > countem(stopwatch, foo, "Czar"); > countem(stopwatch, foo, "windows"); > countem(stopwatch, foo, "Pentium"); > > Console.Read(); > } > > private static void countem(Stopwatch stopwatch, string foo, string pattern) > { > > Regex r = new Regex(pattern, RegexOptions.None); > stopwatch.Start(); > MatchCollection matches = r.Matches(foo); > stopwatch.Stop(); > Console.WriteLine("Word :{0} - Count : {1} - {2} Seconds", pattern, matches.Count.ToString(), stopwatch.Elapsed); > } > } >>