I want to optimize the following small integer program in speed.
My g++ compiler version is 4.3.4 on 32 bit linux.
Please suggest or comment the following ideas.
Some ideas are:
1. use compile flag such as -O3
2. rewrite the bigger function with function object
#include <algorithm>
#include <cstdlib> // for abs()
using namespace std;
const int N = 50;
const int D = 20;
bool bigger (int i) { return abs(i) >= D; }
int main()
{
int seq[N], diff[N];
// initialize seq
// ...
adjacent_difference(seq, seq + N, diff);
int count = count_if(diff + 1, diff + N, bigger);
// ...
return 0;
}