Пример #1
0
        public ActionResult <IEnumerable <string> > Get()
        {
            var        stringDistance = new StringDistance();
            var        watch          = new Stopwatch();
            const long count          = 100;
            const int  length         = 100;
            string     comparestring  = stringDistance.GenerateRandomString(length);
            var        strlist        = new string[count];
            var        steps          = new int[count];

            // prepare string[] for comparison

            Parallel.For(0, count, i => strlist[i] = stringDistance.GenerateRandomString(length));
            Console.WriteLine("已经生成了" + count + "个长度为" + length + "的字符串");

            watch.Start();
            for (int i = 0; i < count; i++)
            {
                steps[i] = stringDistance.LevenshteinDistance(comparestring, strlist[i]);
            }
            watch.Stop();
            Console.WriteLine("完成非并行计算,耗时(ms)" + watch.ElapsedMilliseconds);
            Console.WriteLine("性能比" + 100000d / watch.ElapsedMilliseconds);

            return(Ok("0.0.1"));
        }
Пример #2
0
 private async Task <long> CpuProcess(int time)
 {
     // simulate cpu bound operation for `time` seconds
     for (var i = 1; i <= time; ++i)
     {
         for (int k = 0; k < 10000; ++k)
         {
             string comparestring1 = StringDistance.GenerateRandomString(1000);
         }
         await Task.Delay(100);
     }
     return(time * 10000L);
 }