4 ms·
I love generators in python/javascript/etc but nowadays whenever I reach for C++ it's because I need performance. What's the cost of using this abstraction? Are
by fyp 7y ago
I love generators in python/javascript/etc but nowadays whenever I reach for C++ it's because I need performance. What's the cost of using this abstraction? Are compilers smart enough to convert the equivalent of "for i in range(n)" from python into a regular for loop?
- swsieber 7y agoI don't know. Fun tidbit about Rust: in Rust, using iterators is actually faster than normal loops because the compiler can elide (infer and remove? not entirely sure how to define elude), most of the bounds checking. I'd assume it also gets optimized out in heavily optimized interpreters, like the JVM.
- je42 7y agotry your for loops and equivalents in godbolt.org with different C++ compilers.