# Trick: Faster functions (by using generators)

**URL:** <https://discuss.python.org/t/trick-faster-functions-by-using-generators/95857>\
**Category:** Python Help\
**Created:** [June 17, 2025, 9:17pm UTC](https://discuss.python.org/t/trick-faster-functions-by-using-generators/95857 "2025-06-17T21:17:59Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![Stefan2](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/stefan2/32/18492_2.png) [@Stefan2](https://discuss.python.org/u/Stefan2)\
**Post date:** [June 18, 2025, 1:20pm UTC](https://discuss.python.org/t/trick-faster-functions-by-using-generators/95857/8 "2025-06-18T13:20:43Z")

</div>

Tried a system with Clang as well now:

```python
 27.3 ± 0.1 ns send
 29.7 ± 0.0 ns normal

Python: 3.13.4 (tags/v3.13.4:8a526ec7cbe, Jun 15 2025, 10:56:11) [Clang 18.1.8 (Fedora 18.1.8-2.fc40)]

```

Anyway, yes, this is something I can easily see vary a lot between different Python versions, compilers, compiler options, and machines. Hence the “can be faster” instead of “is faster”.

Mostly I see it as an interesting curiosity. I’ve known it for a few years but almost never used it. The only cases I remember are [this](https://stackoverflow.com/a/75978298) where I also found it neat and scalable to have my predicate function’s state represented by “instruction pointer” (simply writing the different conditions one after the other), and [this](https://github.com/python/cpython/issues/135480#issuecomment-2981254115) where I rather did it to point out that there’s precedent for iterators having non-dunder methods (since I suggested adding one for `itertools.chain` and it struck even me as unusual until I remembered that generator iterators have some).

---

_[View the full topic](https://discuss.python.org/t/trick-faster-functions-by-using-generators/95857)._
