6 ms·
I mean, compared to sequentially comparing thousands of IP addresses (really???), anything would be fast.
by ComputerGuru 8y ago
I mean, compared to sequentially comparing thousands of IP addresses (really???), anything would be fast.
- groestl 8y agoPeople here dismiss the linear search, but for a small number of items (and yes, even thousands can be a small number), I wouldn't be so fast without testing it. Cache locality also has a say here, and depending on the exact circumstances, a linear search might make sense (even more so as a first version).
- gweinberg 8y agoI think the only time it makes sense to use a linear search is if you think the number of items on your list is low enough that it doesn't even matter what data structure you are using. But I would probably use a set rather than a list anyway if only because that more accurately reflects the nature of the data.
- lloeki 8y agoIIRC MySQL just skips using indices and does a linear search when a table size is small enough.
- machinecoffee 8y agoProbably a lot of DB Servers do that - which is why the plan for a query can change as the amount of data per table increases.
- vardump 8y agoI think with AVX2 you could compare 10000 IP addresses in maybe 500 nanoseconds. Assuming they're cached. Uncached maybe 2 microseconds. It'd still not be the greatest idea... but don't underestimate linear scan on a modern CPU.