# PyGen - python style generators

**URL:** <https://discourse.julialang.org/t/pygen-python-style-generators/3451>\
**Category:** Community\
**Tags:** package, announcement\
**Created:** [May 1, 2017, 4:09am UTC](https://discourse.julialang.org/t/pygen-python-style-generators/3451 "2017-05-01T04:09:29Z")\
**Posts on this page:** 1\
**Showing post:** 53

<div class="post-metadata">

**Author:** ![BenLauwens](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/benlauwens/32/2051_2.png) [@BenLauwens](https://discourse.julialang.org/u/BenLauwens)\
**Post date:** [August 31, 2017, 9:08am UTC](https://discourse.julialang.org/t/pygen-python-style-generators/3451/53 "2017-08-31T09:08:06Z")

</div>

… a fair direct implementation:

```julia
const n = 93

@noinline function fibonnaci_direct(a::Int, b::Int)
  b, a+b
end

function test_direct()
  a = zero(Int)
  b = a + one(a)
  for i in 1:n 
    a, b = fibonnaci_direct(a, b)
  end
end

println("Direct: ")
@btime test_direct()

```

Summary of all benchmarks:

```julia
Direct:
  154.587 ns (0 allocations: 0 bytes)
ResumableFunctions:
  414.040 ns (1 allocation: 32 bytes)
Produce/consume:
  37.495 μs (158 allocations: 4.06 KiB)
Channels csize=0:
  106.098 μs (276 allocations: 7.47 KiB)
Channels csize=20:
  23.371 μs (116 allocations: 5.88 KiB)
Channels csize=100:
  13.167 μs (108 allocations: 6.77 KiB)
Closure:
  6.966 μs (83 allocations: 1.31 KiB)
Closure optimised:
  190.277 ns (3 allocations: 64 bytes)
Closure statemachine:
  446.282 ns (4 allocations: 80 bytes)

```

---

_[View the full topic](https://discourse.julialang.org/t/pygen-python-style-generators/3451)._
