如何在两个单独的步骤中运行 MSVC 预处理器和编译器?

发布于 2024-10-13 01:17:33 字数 675 浏览 2 评论 0原文

我想运行 Microsoft Visual Studio 编译器 cl.exe 而不调用预处理器。这可能吗?我认为简单地编译预处理的源代码(使用 /c 标志)将使预处理器以无操作的方式运行,但显然情况并非如此。我做了一些基准测试。这是一个小源文件 (main.cpp),其中只包含一些代码:

#include <iostream>
#include <string>
#include <windows.h>

以下是一些不同的编译器调用及其计时:

1: cl /c main.cpp                             ~1.02s
2: cl /EP main.cpp > main-preprocessed.cpp    ~0.5s
3: cl /c main-preprocessed.cpp                ~0.75s

看来编译预处理的源代码已经快了一些(预处理器没有不需要做任何事情)。然而,1 和 2 之间的差异表明实际的编译器和汇编器只需要多一点 0.5 秒。因此,编译预处理后的源代码(如步骤 3 中所做的那样)比我希望的要慢一些。

有没有办法只运行编译器和汇编器,而不调用预处理器?我对 MSVC6 到 MSVC10 的解决方案感兴趣。

I'd like to run the Microsoft Visual Studio Compiler cl.exe without invoking the preprocessor. Is this possible? I thought that simply compiling preprocessed source code (using the /c flag) would make the preprocessor run being a no-op, but apparently that's not the case. I did a bit of benchmarking. Here's a little source file (main.cpp) which just includes some code:

#include <iostream>
#include <string>
#include <windows.h>

Here are some different compiler invocations and their timings:

1: cl /c main.cpp                             ~1.02s
2: cl /EP main.cpp > main-preprocessed.cpp    ~0.5s
3: cl /c main-preprocessed.cpp                ~0.75s

It seems that compiling preprocessed source code is already a bit faster (the preprocessor doesn't need to do anything). However, the difference between 1 and 2 suggests that the actual compiler and assembler just needs a bit more 0.5s. So compiling the preprocessed source code (as done in step 3) is a bit slower than I hoped.

Is there any way to just run the compiler and assembler, without invoking the preprocessor? I'm interested in solutions for MSVC6 up to MSVC10.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

初熏 2024-10-20 01:17:33

据我所知,没有预处理器就无法运行编译器(不管它什么都不做)。

但是,当您向文件添加写入然后读回该文件时,分离这两个阶段显然会更慢如果不需要执行这些写入操作,它可以将其保存在内存中,并且您可以节省大量等待磁盘写入和读取的时间,

即使您可以禁用预处理器。仍然比同时运行两个阶段慢。

To my knowledge there is no way to run the compiler without the preprocessor (regardless of the fact that it doesn't do anything.

However seperating the 2 stages will obviously be slower as you are adding a write to file and then read back of that file. If it doesn't need to do those writes it can hold it in memory and you save a tonne of time waiting for the disk to be written to & read from.

ie Even if you could disable the pre-processor it would still be slower than running both stages simultaneously.

┾廆蒐ゝ 2024-10-20 01:17:33

您认为预处理器花费的很多时间很可能实际上是用于将大文件写入磁盘的时间。实际上,预处理器所花费的时间只占编译器其余部分所花费时间的一小部分。正常预/编译的一大好处是,编译器可以在预处理器阶段仍在运行时开始编译,可能在单独的线程中或在检测到新的预处理器输出时开始编译。大型预处理器输出可能不需要占用内存(更不用说磁盘),因为它会以较小的块被消耗和覆盖。

It may well be that a lot of the time you think the preprocessor is taking is actually time spent writing that large file to disk. The preprocessor should actually take a tiny percentage of the time that the rest of the compiler takes. A big benefit of a normal pre/compilation is that the the compiler can begin compiling while the preprocessor stage is still running, perhaps in a separate thread or as it detects new preprocessor output. The large preprocessor output may not need to ever occupy memory (let alone disk), as it's consumed and overwritten in smaller chunks.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文