# Is this the maximum perf i can obtain?

**URL:** <https://discourse.julialang.org/t/is-this-the-maximum-perf-i-can-obtain/74022>\
**Category:** Performance\
**Created:** [January 4, 2022, 9:50am UTC](https://discourse.julialang.org/t/is-this-the-maximum-perf-i-can-obtain/74022 "2022-01-04T09:50:08Z")\
**Posts on this page:** 1\
**Showing post:** 12

<div class="post-metadata">

**Author:** ![lrnv](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lrnv/32/19373_2.png) [@lrnv](https://discourse.julialang.org/u/lrnv)\
**Post date:** [January 5, 2022, 9:55am UTC](https://discourse.julialang.org/t/is-this-the-maximum-perf-i-can-obtain/74022/12 "2022-01-05T09:55:25Z")

</div>

> [@djholiver](#):
>
> Why do you need to allocate to slack (or even provide it as a variable) in the two methods?

because I actually need the result for later computations. Look again at my `runtime_test!` function:

```julia
function runtime_test!(rez,slack,D)
    n = length(rez)
    N = length(D)
    rez[1] = exp_and_mean!(slack,D,N)
    for i in 1:n-1
        rez[i+1] = prod_and_mean!(slack,D,N)
    end
    return rez
end

```

You see that the slack is passed along from one function to the other. Actually, if you denote by X the rndom variable that corresponds to the data `D`, my function computes \mathbb E\left(X^k e^{-X}\right), for k \in \{0,...,n-1\}.

> [@djholiver](#):
>
> is there also potentially an error in “prod\_and\_mean” ? do you mean to sum zz (I change to multiple above).
> 
> From your input setup vars, you are passing in slack as a vector of zeros so doesnt this yield zero for all cases in “prod\_and\_mean” ? Obviously they may be intended.

No there is no error in “prod\_and\_mean”, I indeed mean to sum `zz`. Yes this is intended, since `slack` is not expected to be zeros when calling the `prod_and_mean` function, look again at the `runtime_test!` function 🙂

> [@djholiver](#):
>
> Do you have any opportunity to modify all “Ds” before being passing into the functions at all or are they always generated before being called? You might benefit from creating the entire “D” matrix space in exp and not exp forms before executing your functions (you’d also be able to combine them if this is applicable).

I do not understand what you mean. This computation is done only once for a given dataset `D`, I am afraid. The dataset `D` changes from one execution to the next, albeit not completely randomly: I compute it from another dataset `data` as follows:

```julia
data=.... #(sized (10,10000)
for i in 1:n_iterations 
    e = rand(10) # A new one is picked at each iteration 
    D = data'e # now a vector of size 10000
    runtime_test!(rez,slack,D)
    do_something_with!(rez)
end

```

`data` is fixed from one iteration to the other, but `e` is not (and therefore neither `D`, `slack` and `rez`). `rez` is needed for the rest of the computations, but `D` and `slack` are not.

---

_[View the full topic](https://discourse.julialang.org/t/is-this-the-maximum-perf-i-can-obtain/74022)._
