相关疑难解决方法(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万
查看次数

.NET CLR JIT每次都编译每个方法吗?

我知道Java的HotSpot JIT有时会跳过JIT编译方法,如果它希望编译的开销低于在解释模式下运行方法的开销..NET CLR是否基于类似的启发式工作?

.net clr jit

26
推荐指数
2
解决办法
1万
查看次数

标签 统计

.net ×1

c ×1

c# ×1

clr ×1

jit ×1

performance ×1