# Structs and parametric constructors

**URL:** <https://discourse.julialang.org/t/structs-and-parametric-constructors/18684>\
**Category:** New to Julia\
**Created:** [December 15, 2018, 11:48am UTC](https://discourse.julialang.org/t/structs-and-parametric-constructors/18684 "2018-12-15T11:48:07Z")\
**Posts on this page:** 1\
**Showing post:** 12

<div class="post-metadata">

**Author:** ![chakravala](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chakravala/32/6832_2.png) [@chakravala](https://discourse.julialang.org/u/chakravala)\
**Post date:** [December 15, 2018, 3:10pm UTC](https://discourse.julialang.org/t/structs-and-parametric-constructors/18684/12 "2018-12-15T15:10:49Z")

</div>

> [@ckoe-bccms](#):
>
> And what is the real world speed difference for you ?

When I only add the `Function` parameters to the `Define` type, I get basically 0% to 10% improvement.

My original timings look like this

```Julia
julia> newton(:(z^3-1);n=500)|>fatou;
  0.240635 seconds (1.69 M allocations: 58.407 MiB)

```

With the `Define{FT<:Function,QT<:Function,CT<:Function}` definition, I don’t get much improvement

```Julia
julia> newton(:(z^3-1);n=500)|>fatou;
  0.221504 seconds (1.53 M allocations: 50.724 MiB)

```

However, because in my situation there is additional program logic, I added additional `Bool` type paramters to the `Fatou.Define{FT,QT,CT,M,N}` object, which gave me a 10x performance improvement. This time the parameters have additionally `Bool` pair to help decide on Mandelbrot and Newton fractal mode.

```Julia
julia> newton(:(z^3-1);n=500)|>fatou;
  0.020936 seconds (542 allocations: 36.784 KiB)

```

This is because of my iteration function definition, which depends on these true or false values, by including them in the `Fatou.Define` type parameters, the function can specialize on those values

```Julia
# define function for computing orbit of a z0 input
function nf(K::Define{FT,QT,CT,M,N},z0::Complex{Float64}) where {FT,QT,CT,M,N}
    M ? (z = K.seed) : (z = z0)
    zn = 0x00
    while (N ? (K.Q(z,z0)::Float64>K.ϵ)::Bool : (K.Q(z,z0)::Float64<K.ϵ))::Bool && K.N>zn
        z = K.F(z,z0)::Complex{Float64}
        zn+=0x01
    end; #end
    # return the normalized argument of z or iteration count
    return (zn::UInt8,z::Complex{Float64})
end

```

So now it computes much, much faster. However, in my case, having a `Function` parameter alone did not do the trick, it was also necessary to have other parameters also.

> [@ckoe-bccms](#):
>
> return ergebnis

Sprechen sie Deutsch?

---

_[View the full topic](https://discourse.julialang.org/t/structs-and-parametric-constructors/18684)._
