Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 smallest 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?

like image 817
user963241 Avatar asked Aug 03 '26 07:08

user963241


1 Answers

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.

like image 125
sbi Avatar answered Aug 05 '26 22:08

sbi