C language INT type range comparison performance optimization

C language INT type range comparison performance optimization

INT type range comparison optimization, 30%+ performance improvement

befor:
if (x >= min && x <= max) {
    ...
}

after:
if (( (x - min) | (max - x) ) >= 0) {
    ...
}
or
if ((unsigned)(x - min) <= (unsigned)(max - min)) {
    ...
}

Comments

Popular posts from this blog

Python Receiving and parse JSON Data via UDP protocol

ubus lua client method and event registration code demo/example