临时用于鲲鹏920 docker环境下的cpu速度:
using System;
using System.Diagnostics;
using System.Numerics;
using System.Reflection;
using System.Threading.Tasks;
class Program
{
static void Main()
{
// 创建80个任务
var tasks = Enumerable.Range(0, 80)
.Select(index => Task.Run(() => { RunProcess(index); }))
.ToList();
// 等待所有任务完成
Task.WhenAll(tasks).Wait();
}
private static void RunProcess(object index)
{
var stopwatch = new Stopwatch();
stopwatch.Start();
BigInteger sum = 0;
while (stopwatch.ElapsedMilliseconds < 10000)
{
Random random = new Random();
BigInteger a = BigInteger.Pow(2, random.Next(1,32));
BigInteger b = BigInteger.Pow(2, random.Next(1, 32));
sum += 1*a * b/a*b;
}
Console.WriteLine($"Process {index} completed. sum:{sum}");
}
}
主机内直接运行测试:
Docker内运行测试: