Question

Do lfind/lsearch perform better than a typical looping solution that checks each item until it matches? Is there any special sauce/reason that these functions exist?

Was it helpful?

Solution

Probably they are not more efficient that a homebrew version, maybe even a bit less since the comparison function can't be inlined.

But this is certainly not the point with them. They complete the API of the other search functions, in particular bsearch and tsearch.

OTHER TIPS

Measure!

You can only know about performance by measuring. Things are definitely different on your computer and mine (I may even not have a POSIX compiant compiler cannot measure lfind myself). Thinks are different between different runs of a program.

So, if you need to know, try both the lfind and homebrew methods and measure several times.

Anyway ... C library functions may not have been written in C. If your lfind was written in Python I'd bet it would be slower than a homebrew method :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top