相关疑难解决方法(0)

c ++和c#速度比较

当你处理繁重的计算时,当你需要使用原始CPU功率时,我担心C#的速度.

在计算方面,我一直认为C++比C#快得多.所以我做了一些快速测试.第一个测试计算素数<整数n,第二个测试计算一些pandigital数字.第二次测试的想法来自于:Pandigital Numbers

C#素数计算:

using System;
using System.Diagnostics;

class Program
{

    static int primes(int n)
    {

        uint i, j;
        int countprimes = 0;

        for (i = 1; i <= n; i++)
        {
            bool isprime = true;

            for (j = 2; j <= Math.Sqrt(i); j++)

                if ((i % j) == 0)
                {
                    isprime = false;
                    break;
                }

            if (isprime) countprimes++;
        }

        return countprimes;
    }



    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        Stopwatch sw = new Stopwatch();

        sw.Start();
        int …
Run Code Online (Sandbox Code Playgroud)

c# c++ benchmarking

6
推荐指数
4
解决办法
6083
查看次数

标签 统计

benchmarking ×1

c# ×1

c++ ×1