我已经测量了两种计算2的幂的方法的执行时间:
1)内联
result = b * b;
Run Code Online (Sandbox Code Playgroud)
2)通过简单的函数调用
result = Power(b);
Run Code Online (Sandbox Code Playgroud)
在调试模式下运行时,一切都按预期进行:调用函数比在线计算(行中385毫秒与函数调用570毫秒)相比要昂贵得多.
在发布模式下,我希望编译器能够大大加快函数调用的执行时间,因为编译器会在内部内联非常小的Power()函数.但我不希望函数调用比手动内联计算更快.
最令人惊讶的是这种情况:在发布版本中,第一次运行需要109 ms,而第二次运行Power()需要62 ms.
函数调用如何比手动内联更快?
以下是您的复制程序:
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Starting Test");
// 1. Calculating inline without function call
Stopwatch sw = Stopwatch.StartNew();
for (double d = 0; d < 100000000; d++)
{
double res = d * d;
}
sw.Stop();
Console.WriteLine("Checked: " + sw.ElapsedMilliseconds);
// 2. Calulating power with function call
Stopwatch sw2 = Stopwatch.StartNew();
for (int d = …Run Code Online (Sandbox Code Playgroud) 如何在 Visual Studio 加载项工具“Visual Studio 拼写检查器”中设置用户词典的位置?
背景:我想在我的解决方案文件夹中使用用户字典,我可以在版本控制下设置它。通常用户词典存储在 C:\Users\UserName\AppData\Local\EWSoftware\Visual Studio Spell Checker 下
在使用许多标准模板库容器(如std :: set或std:vector)的Microsoft Visual C++(VS 2008/2010)中,您将遇到内存泄漏:
#include <set>
#include <stdlib.h>
#include <crtdbg.h>
#define _CRTDBG_MAP_ALLOC
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
printf("I'm leaking\n");
std::set<int> s;
_CrtDumpMemoryLeaks();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
运行程序后,您将获得如下输出:
Detected memory leaks!
Dumping objects ->
{209} normal block at 0x005E9C68, 20 bytes long.
Data: <h ^ h ^ h ^ > 68 9C 5E 00 68 9C 5E 00 68 9C 5E 00 CD CD CD CD
{208} normal block at 0x005E9C20, 8 bytes long.
Data: < …Run Code Online (Sandbox Code Playgroud) 我有一个非常简单的C#控制台应用程序,帽子对大量元素进行了一些排序(只有几行代码与数组操作).
当我使用F5或Ctrl-F5从Visual Studio IDE启动发布代码时,程序比直接从Win-Explorer启动时慢大约3倍.
41.140 seconds when launched from VS 2010 IDE
13.950 seconds when launched by double-clicking myprogram.exe
Run Code Online (Sandbox Code Playgroud)
为什么???
c# ×2
performance ×2
release ×2
inline ×1
inline-code ×1
launch ×1
memory ×1
memory-leaks ×1
set ×1
stl ×1