Boost文件系统非常慢? [英] Boost filesystem incredibly slow?

查看:108
本文介绍了Boost文件系统非常慢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在学习Boost框架,并且发现了如何列出系统中的所有文件夹和文件, 使用

I am currently in the process of learning the Boost framework, and I have found out how to list all folders and files on my system, using

#include <boost/filesystem.hpp>
#include <boost/foreach.hpp>
#include <iostream>
using namespace std;
int main()
{
    for ( boost::filesystem::recursive_directory_iterator end, dir("C:\\");
       dir != end; ++dir ) {
       cout << *dir << std::endl;
    }
    return 0;
}

但是我唯一的问题是该过程有多慢...我是在做错什么还是仅仅是Microsoft .NET版本列出所有文件的速度更快? 谢谢!

but the only problem I'm having is how slow the process is... am I doing something wrong or is it just that Microsoft's .NET version of listing all files is much faster? Thanks!

推荐答案

您的问题暗示了一个比较,但是您只提供了一半的信息,即您要与之进行比较的代码在哪里?您可以通过多种方法来提高所提供代码的性能,其中一些方法已在上面的注释中提供.

Your question implies a comparison, but you've only provided half the information i.e. where is the code to which you are making the comparison? There are many ways you can increase the performance of the code you have supplied, some of which have been supplied in the comments above.

也就是说,您观察到性能差异的原因很可能可以追溯到C#代码在其上运行的高度托管的环境.您的文件系统很可能在.Net的内存空间中建立索引,而C ++代码和Boost库直接进入文件系统,而没有从Microsoft尝试使.NET环境更高效的方式中受益.没有效率,似乎C#代码比同等质量的C ++代码慢很多.

That said, it's likely that the reason you are observing a performance difference in the first place can probably be traced to the very managed environment on top of which the C# codes runs. It's quite likely that your filesystem is indexed in .Net's memory space while your C++ code and the Boost library are going directly to the filesystem and not benefitting from one of the ways Microsoft has tried to make the .NET environment more efficient. Without the efficiencies, it seems more likely that C# code would be orders of magnatude slower than compiled C++ code of the same quality.

这篇关于Boost文件系统非常慢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆