简体   繁体   English

小单元测试,msvc

[英]small unit tests , msvc

When I do small unit tests (small exe that calls my function from my library, or calls a piece of code literally embedded before main(), it seems it takes 50 times quicker in Linux than in msvc:当我进行小型单元测试(从我的库中调用我的 function 或调用在 main() 之前嵌入的一段代码的小型 exe 时,Linux 中的速度似乎比 msvc 中快 50 倍:

1) In Linux: 1) 在 Linux 中:

vi test1.c; vi test1.c; cut-and-paste includes.剪切和粘贴包括。 cut-and-pase code.剪切和粘贴代码。 add int main(int argc, char **argv) { declare_data;添加 int main(int argc, char **argv) { declare_data; call_my_function(); call_my_function(); }:wq. }:wq。 cc test1.c &&./a.out done every step takes seconds, if not. cc test1.c &&./a.out 完成每一步都需要几秒钟,如果没有的话。 helper scripts make it seconds.帮助脚本让它秒。

2) In msvc: 2) 在 msvc 中:

create console project.创建控制台项目。 until project creation is finished, it is already more time than whole (1).直到项目创建完成,它已经比整个(1)更多的时间。 paste code.粘贴代码。 fiddle with project settings.摆弄项目设置。 try to pass argv.尝试通过 argv。 try to pass different argv.尝试传递不同的 argv。

It seems everything is x10 times much slower than in Linux.似乎一切都比 Linux 慢 10 倍。

In your experience, how small unittests can be created and done really quickly -- in seconds -- in msvc?根据您的经验,在 msvc 中可以在几秒钟内真正快速地创建和完成小型单元测试?

Nothing is stopping you from compiling and running your MSVC code from the command line.没有什么能阻止您从命令行编译和运行 MSVC 代码。 The actual compiler is a command-line tool, so if the IDE is getting in your way, just bypass it.实际的编译器是一个命令行工具,因此如果 IDE 妨碍您,请绕过它。 You could even find a Windows port of Vi, and you'd have pretty much exactly the same workflow as on Linux.您甚至可以找到 Vi 的 Windows 端口,并且您将拥有与 Linux 几乎完全相同的工作流程。

But if you choose to use a heavy-duty IDE which is designed for working with large code bases, then yes, there'll be quite a bit of overhead.但是,如果您选择使用专为处理大型代码库而设计的重型 IDE,那么是的,会有相当多的开销。

Unless you write a MSVC addin to make it faster and easier to do these things.除非您编写 MSVC 插件以使其更快、更轻松地完成这些事情。 (And if you do, please make it public, because a lot of us would find it useful. ;)) (如果你这样做了,请将其公开,因为我们很多人会发现它很有用。;))

If you are using Visual C++ only for building your test(s), you can use MinGW instead.如果您仅使用 Visual C++ 来构建您的测试,则可以改用MinGW

It looks like your after a VC++ solution, but for others who happen across this question there is the Temporary Projects feature of Visual Studio.它看起来像是你在使用 VC++ 解决方案,但对于遇到这个问题的其他人来说,有 Visual Studio 的临时项目功能。 Only certain project templates support this, not any c++ that I can find.只有某些项目模板支持这一点,而不是我能找到的任何 c++。 You could create your own template?您可以创建自己的模板吗? See MSDN for more information on configuring Temporary Projects, it is available in 2005 to 2010 Visual Studios.有关配置临时项目的更多信息,请参阅MSDN ,它在 2005 至 2010 Visual Studios 中可用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM