如何使用Boost Asio减少编译时间 [英] How to reduce compilation times with Boost Asio

查看:255
本文介绍了如何使用Boost Asio减少编译时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Boost.Asio是一个伟大的库,但它有一个巨大的缺点 - extreamly缓慢的编译时间。 HTTP协议(约1K行代码)的简单实现(真的很简单)需要大约13.5s编译GCC 4.4!



我尝试使用PCH,但它没有提高编译时间太多(约1s。)。



那么有什么教程如何使Boost.Asio编译时间更快?

$ b



我使用例如: io_service

code>, tcp :: ip :: sockets tcp :: ip :: acceptor deadline_timer ,缓冲
和几个函数,如 async_read async_write



有任何建议吗?



PS:我可以随时使用pimpl。 b $ b

解决方案


  • 你使用 boost :: lambda c $ c> boost :: bind 来构造完成处理程序?
    boost :: bind 更简单=>编译速度更快。

  • 您可以使用#pragma message )看看是否包含#include或实际的编译需要时间。我使用这个与MSVS看到有时,大多数编译时间是在任何代码之前的.cpp,其他时间,它大多是在后。这可以帮助您分析编译器的性能。 (但是,如果预处理器/ #include是快速的,并且在任何其他之前运行,它不会给你太多)


Boost.Asio is great library but it has one huge drawback -- extreamly slow compilation times. A simple implementation (really simple) of HTTP protocol (about 1k lines of code) requires about 13.5s to compile under GCC 4.4!

I tryed to use PCH but it does not improve compilation times too much (about 1s. only).

So are there any tutorials on how to make Boost.Asio compilation times faster?

For example what headers should I exactly include for what class.

I use for example: io_service, tcp::ip::sockets, tcp::ip::acceptor, deadline_timer, buffers and few functions like async_read, async_write.

Any suggestions?

P.S.: I do use pimpl whenever I can.

解决方案

  • Do you use boost::lambda or boost::bind to construct your completion handlers? boost::bind is less complex => compiles faster.
  • You can profile the compiler with #pragma message() to see if it's the #include-ing or the actual compiling that takes time. I've used this with MSVS to see that sometimes, most of the compilation time is before any code in the .cpp, and other times, it's mostly after. That could help you to profile your compiler's performance. (But, if the preprocessor/#include is fast and run before anything else, it won't give you much)

这篇关于如何使用Boost Asio减少编译时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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