News for hackers. Stuff that matters.
Re:What Learning APL Taught Me About Python by veber-alex on Wednesday August 16, 2023 @07:49PM (#37155408)
> Obviously if the function is on a hot path iterating and summing with a number is far more efficient versus filtering.

I got curious and checked this in Rust, the generated assembly is the same!

https://rust.godbolt.org/z/jhGWdYPz1

Re:What Learning APL Taught Me About Python by proto_lambda on Thursday August 17, 2023 @03:15AM (#37158283)
Because you're not actually creating a filtered list, you're just filtering an iterator.
Re:What Learning APL Taught Me About Python by nonameiguess on Thursday August 17, 2023 @11:10AM (#37162887)
Neither of your examples is doing what the parent suggested as an alternative, which is simply looping and counting rather than creating an anonymous function to repeatedly call. I doubt this makes an enormous difference in practice, but you can see your generated assembly doing all the argument passing and stack frame setup, which is extra instructions compared to just straight looping and counting.