Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
VFP vs C# String handling
Message
From
22/05/2011 11:17:52
 
 
To
22/05/2011 10:38:35
General information
Forum:
Visual FoxPro
Category:
Other
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Miscellaneous
Thread ID:
01511379
Message ID:
01511399
Views:
85
Interesting results. I wonder what the difference between RegEx and IndexOf would be.


>Just duplicated one of Steve's tests, since he added "Locating sub-strings in strings is something VFP does really well."
>
>VFP :
>
>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
>
>
>
>Times ranged from : Pentium 0 occurs - .147 seconds to Russia 775 occurs .185 seconds
>
>Here's C#
>
>
>    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);
>        }
>    }
>
>
>Ranges from Russia - 775 occurs - .0000065 seconds to Pentium - 0 occurs - .0000130 seconds
>
>( interesting that the fastest was the most finds and 0 was the slowest - Anna - 293 - .00000082 seconds etc )
>
Craig Berntson
MCSD, Microsoft .Net MVP, Grape City Community Influencer
Previous
Reply
Map
View

Click here to load this message in the networking platform