←back to thread

87 points mkalioby | 1 comments | | HN request time: 0.207s | source
Show context
abdullahkhalids ◴[] No.42190985[source]
I don't understand why numeric filters are included. The library is written in python, so shouldn't a lambda function based filter be roughly as fast but much easier/clearer to write.
replies(2): >>42191496 #>>42192896 #
yunohn ◴[] No.42192896[source]
AFAICT this should filter in one pass, so it would be faster than multiple lambdas, or this plus a lambda for numeric.
replies(1): >>42199784 #
me-vs-cat ◴[] No.42199784[source]
If you are concerned that your Python is making single-digit extra function calls, then you should be using a different language. (However, you might want a C extension that can be used from Python.)

That said, it's trivial to apply multiple filter lambdas in one pass -- the most natural way is a comprehension.

Still, you might be surprised by how fast filter(cond_1, filter(cond_2, data)) actually is. The OP didn't present that performance comparison, nor can I see any reason they gave to avoid comprehensions.

replies(1): >>42205917 #
yunohn ◴[] No.42205917[source]
Why would you assume single digit extra calls? If the list is N million, then you would do a constant multiple of iterations of that. That’s a non trivial overhead in production applications.
replies(1): >>42211162 #
1. me-vs-cat ◴[] No.42211162[source]
You're choosing the weakest strawman interpretation and ignoring the rest of what I said.

Bye, have fun!