简体   繁体   English

进行文件操作时,C ++程序在Windows和Linux上的运行速度要慢得多?

[英]C++ program runs much slower on Windows vs Linux when doing file operations?

I use an open source project called ChatScript for natural language processing app development. 我使用一个名为ChatScript的开源项目进行自然语言处理应用程序开发。

When you execute a build operation with ChatScript, it scans all the script files that comprise your chat-bot. 当您使用ChatScript执行构建操作时,它将扫描构成您的聊天机器人的所有脚本文件。 In my case, that's hundreds of files. 就我而言,这是数百个文件。 This process takes nearly 30 times longer on Windows 8.1 than it does on Ubuntu 16.04 . Windows 8.1上,此过程花费的时间比在Ubuntu 16.04上花费将近30倍 Therefore I do use Linux for much of my work, but there is a part of my work that I have to do on Windows because of certain associated tools, so I would like to modify the code base so that Windows ChatScript compiles are as fast as on Linux. 因此,我的大部分工作中使用Linux,但是由于某些相关工具,我必须在Windows上做一部分工作,因此我想修改代码库,以便Windows ChatScript的编译速度与在Linux上。

Can anyone think of a reason the code would run so much slower on Windows vs. Linux ? 谁能想到在WindowsLinux上代码运行得这么慢的原因吗? Are there some C++ file operation codes (read/write/etc.) that are known to be much slower on Windows compared to Linux due to variances in the C++ run-time libraries running on each platform? 是否有一些C ++的文件操作代码(读/写/等等)被称为是在Windows得多Linux相比,由于差异在C ++运行时库每个平台上运行?

By "code running slow" in your last paragraph I'm assuming from context that you're referring to the compiler??? 通过在上一段中“代码运行缓慢”,我从上下文假设您是指编译器???

I've encountered frequently and consistently over many years a general, significant performance difference between linux and Windows in disk I/O. 多年来,我在磁盘I / O中经常且始终如一地遇到Linux和Windows之间普遍的,显着的性能差异。 NTFS (Windows file system) and the linux file systems handle the situation of lots of files differently, and linux is always quicker in the circumstances I've been in. NTFS(Windows文件系统)和linux文件系统以不同的方式处理许多文件的情况,在我去过的情况下,linux总是更快。

You may benefit from some of the pointers in answers to questions like How do I get Windows to go as fast as Linux for compiling C++? 您可能会从一些问题的答案中受益,例如如何使Windows像Linux一样快地运行C ++? , like defragmenting your windows drive, and checking how the compiler optimisations are configured; ,例如对Windows驱动器进行碎片整理,并检查如何配置编译器优化; some of them can slow down the compiler (although an aggressive compiler optimisation setting can slow the compiler down, you produce a faster executable at the end, but that might be something you switch to after most of your development is done). 其中一些会减慢编译器的速度(尽管积极的编译器优化设置会减慢编译器的速度,但最终会生成更快的可执行文件,但这可能是在大多数开发完成后切换到的东西)。

But doing all those things for me has never got the Windows compile to be quicker than on linux using equivalent disk hardware, not once. 但是,为我做所有这些事情从来没有使Windows的编译速度比使用等效磁盘硬件的Linux更快。 If your code is on the one disk and sourced for both compiles, any improvement you'll see in the Windows build (eg because the code's put on an SSD) will likely be replicated in an improvement in the linux build as well. 如果您的代码在一个磁盘上并且可以同时进行两种编译,则您在Windows版本中会看到的任何改进(例如,因为代码放在SSD上)也可能会在Linux版本中得到复制。

Just to confirm I found the same thing. 只是为了确认我发现了同样的事情。 Ran the same Chatscript scripts on an average Mac and on a fast XPS 15. The Mac compiled the code 30-50 times faster than Windows. 在普通Mac和快速XPS 15上运行相同的Chatscript脚本。Mac编译代码的速度比Windows快30-50倍。 What's weird is ChatScript was originally developed for Windows. 奇怪的是,ChatScript最初是为Windows开发的。 I also have not worked out why such a gigantic lag, in spite of the Windows PC hardware being much more powerful than the Mac running the script. 尽管Windows PC硬件比运行脚本的Mac强大得多,但我也没有弄清楚为什么会有如此巨大的滞后。

So I have come across both an explanation and a (partial) solution. 因此,我遇到了一个解释和一个(部分)解决方案。 There are two areas of lag in Windows compared to Linux: 与Linux相比,Windows有两个滞后区域:

  • Networking behaviour. 网络行为。 According to the creator of ChatScript, Bruce Wilcox, the Windows server code is worse under the hood, and is also implemented worse in ChatScript for Windows vs ChatScript for Linux. 根据ChatScript的创建者Bruce Wilcox的说法,Windows服务器代码在后台更差,并且在Windows的ChatScript和Linux的ChatScript中也实现得较差。 The lag here is however minor. 然而,这里的滞后很小。

  • Build times. 构建时间。 This is where building the bot in Linux takes 10-20 seconds and on Windows 4-5 minutes. 这是在Linux中构建机器人的时间为10-20秒,而在Windows中则为4-5分钟。 Turns out that the reason is the antivirus: 原来原因是杀毒软件:

"Curious about the huge discrepancy, one of our hardware engineers “对于巨大的差异感到好奇,我们的一位硬件工程师
did some profiling and found the real culprit to be the anti-virus 做了一些分析,发现真正的罪魁祸首是反病毒
software. 软件。 Disabling the real-time virus protection feature of 禁用实时病毒防护功能
Windows Defender brought the 4 minutes down to 14 seconds ! Windows Defender将4分钟缩短为14秒 Even 甚至
keeping Windows Defender active, but excluding the 保持Windows Defender处于活动状态,但不包括
ChatScript-master folder solved much of the slowdown problem, ChatScript-master文件夹解决了许多减速问题,
resulting in about 20 s for :build 0 to complete ." ( https://www.chatbots.org/ai_zone/viewthread/3575/ ) :build 0完成大约需要20秒 。”( https://www.chatbots.org/ai_zone/viewthread/3575/

So for OP, if you exclude CS from Windows Defender, or switch it off, the build differential will largely disappear. 因此,对于OP,如果从Windows Defender中排除CS或将其关闭,则构建差异​​将基本消失。

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

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