• .NET Core到底有多强?


    测试代码:
    C# Release 未优化

    class Program
        {
            static long counter = 0;
            static void Main(string[] args)
            {
                for (int m = 0; m < 100; m++)
                {
                    Stopwatch s = new Stopwatch();
                    s.Start();
                    for (long i = 0; i < 200000000; i++)
                    {
                        counter = counter * 2 + 3;
                    }
                    s.Stop();
                    Console.WriteLine(s.Elapsed.TotalMilliseconds + " ms");
                }
                Console.ReadLine();
            }
        }
    

    Core 2.2

    Framework 4.6.1

    C# Release 优化

    class Program
        {
            static long counter = 0;
            static void Main(string[] args)
            {
                for (int m = 0; m < 100; m++)
                {
                    Stopwatch s = new Stopwatch();
                    s.Start();
                    long temp = counter;
                    for (long i = 0; i < 200000000; i++)
                    {
                        temp = temp * 2 + 3;
                        counter = temp;
                    }
                    s.Stop();
                    Console.WriteLine(s.Elapsed.TotalMilliseconds + " ms");
                }
            }
        }
    

    Core 2.2

    Framework 4.6.1

    go 未优化(照抄C#)

    var counter int64 = 0
    func ExampleLinq_3() {
    	for m := 0; m < 100; m++ {
    		t1 := time.Now()
    		for i := 0; i < 200000000; i++ {
    			counter = counter*2 + 3
    		}
    		fmt.Println("用时:", time.Now().Sub(t1))
    	}
    	// Output:
    }
    

    go 优化(照抄C#)

    var counter int64 = 0
    func ExampleLinq_4() {
    	for m := 0; m < 100; m++ {
    		t1 := time.Now()
    		temp := counter
    		for i := 0; i < 200000000; i++ {
    			temp = temp*2 + 3
    			counter = temp
    		}
    		fmt.Println("用时:", time.Now().Sub(t1))
    	}
    	// Output:
    }
    

    java 8 未优化(照抄C#)

    java 8 优化(照抄C#)

    由于go没有静态变量

    .net core 非静态

    java 8

  • 相关阅读:
    Linux查看所有用户用什么命令
    Sudoku Solver
    Restore IP Addresses
    Implement strStr()
    Insert Interval
    Recover Binary Search Tree
    First Missing Positive
    Rotate List
    Longest Palindromic Substring
    4Sum
  • 原文地址:https://www.cnblogs.com/kingreatwill/p/10650375.html
Copyright © 2020-2023  润新知