# Performant way to create ntuple?

**URL:** <https://discourse.julialang.org/t/performant-way-to-create-ntuple/5783>\
**Category:** General Usage\
**Tags:** ntuple\
**Created:** [September 8, 2017, 11:23am UTC](https://discourse.julialang.org/t/performant-way-to-create-ntuple/5783 "2017-09-08T11:23:44Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![tkoolen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkoolen/32/1603_2.png) [@tkoolen](https://discourse.julialang.org/u/tkoolen)\
**Post date:** [September 8, 2017, 1:34pm UTC](https://discourse.julialang.org/t/performant-way-to-create-ntuple/5783/2 "2017-09-08T13:34:36Z")

</div>

This is [performance of captured variables in closures · Issue #15276 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/15276). You can work around it [using a let block](https://github.com/JuliaLang/julia/issues/15276#issuecomment-297596373)

```julia
using BenchmarkTools
@noinline g(x) = x[1]

function f1(M, ::Type{Val{N}}) where N
    s = 0
    for j = 1:M
        let j = j
            x = ntuple(i -> i + j, Val{N})
            s += g(x)
        end
    end
    return s
end

```

---

_[View the full topic](https://discourse.julialang.org/t/performant-way-to-create-ntuple/5783)._
