开发者

Writing algorithm functions for STL

I have a std::set which is of type point

struct point
{
  int x;
  int y;
  int z;
};

Suppose I want to perform three different operation on each variable in set i.e

  • Find the sm开发者_如何学运维allest number from x variables.
  • Get missing elements from y variables using set difference.
  • Get product of all z variables.

At this point, should i use three predefined alogrithmic functions in sequence or should I write my own alogrithm which would perform all three operations by iterating over the set the once?


Even if you get a ten-fold speed increase, if that piece of code only uses 5% of your application's time, you've just decreased the execution time to 95%. So, unless you know this is a real bottleneck in your application, don't waste time trying to optimize it. And the only way to know this is through profiling.


Start to use 3 functions in sequence. If you get performance issues try to write your own algorithm.

Premature optimization is evil.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜