Optimal (Time paradigm) solution to check variable within boundary

Posted by kumar_m_kiran on Stack Overflow See other posts from Stack Overflow or by kumar_m_kiran
Published on 2010-05-21T17:16:01Z Indexed on 2010/05/21 17:20 UTC
Read the original article Hit count: 122

Filed under:
|
|

Hi All,

Sorry if the question is very naive.
I will have to check the below condition in my code

0 < x < y
i.e code similar to if(x > 0 && x < y)

The basic problem at system level is - currently, for every call (Telecom domain terminology), my existing code is hit (many times). So performance is very very critical, Now, I need to add a check for boundary checking (at many location - but different boundary comparison at each location).

At very normal level of coding, the above comparison would look very naive without any issue. However, when added over my statistics module (which is dipped many times), performance will go down.

So I would like to know the best possible way to handle the above scenario (kind of optimal way for limits checking technique). Like for example, if bit comparison works better than normal comparison or can both the comparison be evaluation in shorter time span?

Other Info

x is unsigned integer (which must be checked to be greater than 0 and less than y). y is unsigned integer.
y is a non-const and varies for every comparison.
Here time is the constraint compared to space.
Language - C++.

Now, later if I need to change the attribute of y to a float/double, would there be another way to optimize the check (i.e will the suggested optimal technique for integer become non-optimal solution when y is changed to float/double).

Thanks in advance for any input.


PS : OS used is SUSE 10 64 bit x64_64, AIX 5.3 64 bit, HP UX 11.1 A 64.

© Stack Overflow or respective owner

Related posts about c++

Related posts about variables