SQLite Forum

SQLITE_WITHIN macro with one compare operator

SQLITE_WITHIN macro with one compare operator

(1) By Martijn (Martijn81) on 2021-07-17 13:19:17 [source]


This macro now looks like:

#define SQLITE_WITHIN(P,S,E) (((uptr)(P)>=(uptr)(S))&&((uptr)(P)<(uptr)(E)))

But it can also be rewritten as:

#define SQLITE_WITHIN(P,S,E) ((uptr)((uptr)(P)-(uptr)(S))<((uptr)(E)-(uptr)(S)))

Or is this UB ? I'm just curious, because this seems to be a bit faster..

(2) By Richard Hipp (drh) on 2021-07-17 14:47:05 in reply to 1 [link] [source]

Cachegrind tells me that your rewrites is actually a little slower, on the standard SQLite performance test benchmark. I get 1,035,083,032 CPU cycles with the existing SQLITE_WITHIN and 1,035,107,651 CPU cycles with your rewrite. Your rewrite also makes the executable 45 bytes larger.

What performance measurement tool is telling you that the rewrite is faster? The numbers above are using cachegrind on a x64 with a binary generated using gcc 5.4.0 and -Os.

(3) By Martijn (Martijn81) on 2021-07-17 15:30:14 in reply to 2 [link] [source]

I didn't measured it myself. My 'knowledge' is from this topic:


Next time i will measure..