Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Diagnostics;
- namespace ConsoleApplication15
- {
- class Program
- {
- static bool IsDigitsOnlyFOREACH(string str)
- {
- foreach (char c in str)
- {
- if (c < '0' || c > '9')
- return false;
- }
- return true;
- }
- static bool IsDigitsOnlyFOR(string str)
- {
- for (int i = 0; i < str.Length;i++ )
- {
- if (str[i] < '0' || str[i] > '9')
- return false;
- }
- return true;
- }
- static bool IsDigitsOnlyALL(string str)
- {
- return str.All(c => c < '0' || c > '9');
- }
- static bool IsDigitsCharIsDigit(string str)
- {
- return str.All(c => char.IsDigit(c));
- }
- static bool IsDigitsOnlyPALL(string str)
- {
- bool res= false;
- str.AsParallel().ForAll(
- c =>
- { if (c < '0' || c > '9') res = false;}
- );
- return res;
- }
- static void Main(string[] args)
- {
- string test = CreateTestData();
- TEST(IsDigitsOnlyFOREACH, test);
- TEST(IsDigitsOnlyALL, test);
- TEST(IsDigitsOnlyFOR, test);
- TEST(IsDigitsOnlyPALL, test);
- TEST(IsDigitsCharIsDigit, test);
- Console.Read();
- }
- private static void TEST(Func<string,bool> cmd,string data)
- {
- var sw = new System.Diagnostics.Stopwatch();
- sw.Start();
- for (int i = 0; i < 1000; i++)
- {
- Trace.Write(cmd.Invoke(data));
- }
- sw.Stop();
- Console.WriteLine("method:" + cmd.Method.Name + " time: " + sw.ElapsedMilliseconds);
- }
- private static string CreateTestData()
- {
- string test = "123456677876965727625623565276863725623625362346527653836593783674567745454544276737763337367867342536578342657234657623498056062309";
- for (int i = 0; i < 12; i++)
- {
- test += test;
- }
- return test;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement