相关疑难解决方法(0)

C#vs C - 性能差异很大

我发现C anc C#中类似代码之间存在巨大的性能差异.

C代码是:

#include <stdio.h>
#include <time.h>
#include <math.h>

main()
{
    int i;
    double root;

    clock_t start = clock();
    for (i = 0 ; i <= 100000000; i++){
        root = sqrt(i);
    }
    printf("Time elapsed: %f\n", ((double)clock() - start) / CLOCKS_PER_SEC);   

}
Run Code Online (Sandbox Code Playgroud)

而C#(控制台应用程序)是:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            DateTime startTime = DateTime.Now;
            double root;
            for (int i = 0; i <= 100000000; i++)
            {
                root = Math.Sqrt(i);
            } …
Run Code Online (Sandbox Code Playgroud)

c c# performance

92
推荐指数
10
解决办法
8万
查看次数

标签 统计

c ×1

c# ×1

performance ×1