一般C ++性能改进提示 [英] General C++ Performance Improvement Tips

查看:80
本文介绍了一般C ++性能改进提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可能指点我的文章,或写一些提示在这里关于一些c ++编程习惯一般有效(没有真正的弊端),并提高性能?我不是指编程模式和算法复杂性 - 我需要一些小东西,比如你如何定义你的函数,要做的事情/避免在循环中,什么在堆栈上分配,堆上什么,等等。

Could someone point me to an article, or write some tips right here about some c++ programming habits that are generally valid (no real drawbacks) and improves performance? I do not mean programming patterns and algorithm complexity - I need small things like how you define your functions, things to do/to avoid in loops, what to allocate on the stack, what on the heap, and so on.

这不是关于如何使一个特定的软件更快,也不是关于如何创建一个干净的软件设计,而是编程习惯 - 如果你总是应用他们,你会使你的代码,

It's not about making a particular software faster, also it's not about how to create a clean software design, but rather programming habits that - if you always apply them, you will make your code rather a little bit faster than a little bit slower.

感谢:)

推荐答案

Effective C ++ 更有效的C ++ 有效的STL C ++编码标准符合这一条。

一个简单的例子这样的提示:如果可能,使用preincrement(++ i)而不是postincrement(i ++)。这对迭代器尤其重要,因为后增量涉及复制迭代器。您优化器可以可以撤消此操作,但是,不是任何额外的工作,写预增量,所以为什么要冒风险?

A simple example of such a tip: use preincrement (++i) rather than postincrement (i++) when possible. This is especially important with iterators, as postincrement involves copying the iterator. You optimizer may be able to undo this, but it isn't any extra work to write preincrement instead, so why take the risk?

这篇关于一般C ++性能改进提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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