Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Program
- {
- internal static string CreateString(int stringLength)
- {
- Random rd = new Random();
- const string allowedChars = "ABCDEFGHJKLMNOPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz0123456789!@$?_-";
- char[] chars = new char[stringLength];
- for (int i = 0; i < stringLength; i++)
- {
- chars[i] = allowedChars[rd.Next(0, allowedChars.Length)];
- }
- return new string(chars);
- }
- static Dictionary<char, int> CountCharsInStr(string str)
- {
- return str
- .Where(c => ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')))
- .GroupBy(char.ToLower)
- .ToDictionary(g => g.Key, g => g.Count());
- }
- static void Main(string[] args)
- {
- string[] strings = new string[1000];
- for (int i = 0; i < 1000; i++)
- {
- strings[i] = CreateString(10000);
- }
- var watch = System.Diagnostics.Stopwatch.StartNew();
- for (int i = 0; i < 1000; i++)
- {
- CountCharsInStr(strings[i]);
- }
- watch.Stop();
- var elapsedMs = watch.ElapsedMilliseconds;
- Console.WriteLine(elapsedMs);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement