c#、c++都把new提到intperf()的外面,又跑了一下,c++的略快那么一点点
这个new操作如果需要的内存大,很可能会走VirtualAlloc()进入内核态,也就是有开销。
c:\temp\test_LIEF\ConsoleApplication1\x64\Release>ConsoleApplication1.exe
time: 12.469 (GetTickCount64)
time: 12.473 (QueryPerformanceCounter)
c:\temp\test_LIEF\ConsoleApplication1\x64\Release>ConsoleApplication1.exe
time: 12.406 (GetTickCount64)
time: 12.395 (QueryPerformanceCounter)
c:\temp\test_LIEF\ConsoleApplication1\x64\Release>ConsoleApplication1.exe
time: 12.578 (GetTickCount64)
time: 12.574 (QueryPerformanceCounter)
c:\temp\test_LIEF\ConsoleApplication1\x64\Release>ConsoleApplication1.exe
time: 12.438 (GetTickCount64)
time: 12.446 (QueryPerformanceCounter)
c:\temp\test_LIEF\ConsoleApplication1\x64\Release>ConsoleApplication1.exe
time: 12.547 (GetTickCount64)
time: 12.541 (QueryPerformanceCounter)
c:\temp\test_LIEF\ConsoleApplication1\x64\Release>ConsoleApplication1.exe
time: 12.407 (GetTickCount64)
time: 12.409 (QueryPerformanceCounter)
//-------------------------------------------------------------------------
C:\temp\CsharpConsoleApp1\CsharpConsoleApp1>dotnet run CsharpConsoleApp1.dll
C:\Program Files\dotnet\sdk\6.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.targets(134,5): warning NETSDK1182: 不支持在 Visual Studio 2019 中以 .NET 6.0 为目标。 [C:\temp\CsharpConsoleApp1\CsharpConsoleApp1\CsharpConsoleApp1.csproj]
12.953 (Environment.TickCount)
12.943 (QueryPerformanceCounter)
C:\temp\CsharpConsoleApp1\CsharpConsoleApp1>dotnet run CsharpConsoleApp1.dll
C:\Program Files\dotnet\sdk\6.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.targets(134,5): warning NETSDK1182: 不支持在 Visual Studio 2019 中以 .NET 6.0 为目标。 [C:\temp\CsharpConsoleApp1\CsharpConsoleApp1\CsharpConsoleApp1.csproj]
12.844 (Environment.TickCount)
12.833 (QueryPerformanceCounter)
C:\temp\CsharpConsoleApp1\CsharpConsoleApp1>dotnet run CsharpConsoleApp1.dll
C:\Program Files\dotnet\sdk\6.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.targets(134,5): warning NETSDK1182: 不支持在 Visual Studio 2019 中以 .NET 6.0 为目标。 [C:\temp\CsharpConsoleApp1\CsharpConsoleApp1\CsharpConsoleApp1.csproj]
12.813 (Environment.TickCount)
12.810 (QueryPerformanceCounter)
C:\temp\CsharpConsoleApp1\CsharpConsoleApp1>dotnet run CsharpConsoleApp1.dll
C:\Program Files\dotnet\sdk\6.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.targets(134,5): warning NETSDK1182: 不支持在 Visual Studio 2019 中以 .NET 6.0 为目标。 [C:\temp\CsharpConsoleApp1\CsharpConsoleApp1\CsharpConsoleApp1.csproj]
12.843 (Environment.TickCount)
12.834 (QueryPerformanceCounter)
C:\temp\CsharpConsoleApp1\CsharpConsoleApp1>dotnet run CsharpConsoleApp1.dll
12.844 (Environment.TickCount)
12.851 (QueryPerformanceCounter)
C:\temp\CsharpConsoleApp1\CsharpConsoleApp1>dotnet run CsharpConsoleApp1.dll
12.766 (Environment.TickCount)
12.776 (QueryPerformanceCounter)
C:\temp\CsharpConsoleApp1\CsharpConsoleApp1>dotnet run CsharpConsoleApp1.dll
12.859 (Environment.TickCount)
12.850 (QueryPerformanceCounter)
C:\temp\CsharpConsoleApp1\CsharpConsoleApp1>dotnet run CsharpConsoleApp1.dll
12.781 (Environment.TickCount)
12.790 (QueryPerformanceCounter)
【 在 finlab 的大作中提到: 】
: 赞!
: 每次运行时间有波动,不过大体说明问题了
: C#基本运算并不慢,但是框架基础类开销相对大,一层层积累下来差异就体现出来了
: ...................
--
修改:z16166 FROM 114.245.195.*
FROM 114.245.195.*