Re: min/max by value - 25% faster
On Feb 22, 4:56 am, Eirik <eirik.olims...@gmail.com> wrote:
I see a ~25% increase in performance (VC2010 SP1) when adding an
overload that takes integers by value instead of const references.
Why are these not implemented as a part of STL for int, double, etc..?
#define MIN(a, b) a<b?a:b
#define MAX(a, b) a>b?a:b
namespace std
{
inline const int min(int const a, int const b)
{
return MIN(a, b);
}
inline const int max(int const a, int const b)
{
return MAX(a, b);
}
}
caller:
{
std::vector<int> v(2);
v[0] = get_some_random_number();
v[1] = get_some_random_number();
int m = std::min(v[0], v[1]); // ~25% faster when the o=
verload above
is chosen
}
As others have asked, what compiler, what platform, what compiler
options - specifically is optimization enabled?