# BenchmarkTools @btime breaks my function arguments

**URL:** <https://discourse.julialang.org/t/benchmarktools-btime-breaks-my-function-arguments/103710>\
**Category:** New to Julia\
**Created:** [September 10, 2023, 12:02am UTC](https://discourse.julialang.org/t/benchmarktools-btime-breaks-my-function-arguments/103710 "2023-09-10T00:02:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Leibniz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leibniz/32/217959_2.png) [@Leibniz](https://discourse.julialang.org/u/Leibniz)\
**Post date:** [September 10, 2023, 12:02am UTC](https://discourse.julialang.org/t/benchmarktools-btime-breaks-my-function-arguments/103710/1 "2023-09-10T00:02:16Z")

</div>

I have a package with an exported function that I want to benchmark.

When I run the function without the `@btime` macro, it executes flawlessly. With the macro, however, it seems to mess with the input arguments in a way where an exception is triggered that I wrote myself:

```julia
using MyPackage
using BenchmarkTools

observables = [(x,p,force) -> x[1], (x,p,force) -> x[2]]
observable_names = ["x", "y"]

@btime simulate(// some other arguments//,  
                observables=observables, observable_names=observable_names)

```

The function `simulate` calls another function that is supposed to check the validity of passed input arguments:

```julia
## in function simulate(...)
argument_check(//some other arguments//, observables, observable_names)

```

The definition of that function:

```julia
Function argument_check(// other arguments// 
                        observables::Vector{<:Function}, 
                        observable_names::Vector{String}
                                            )
// some exceptions

    if size(observables)!= size(observable_names)
        throw(DimensionMismatch("Number of observable names does not correspond to number of passed observables!\n"))
    end

// some more exceptions

end

```

This exception is triggered when the macro @btime is used with `simulate`.  
Why does the macro mess with what happens in my function?

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [September 10, 2023, 12:50am UTC](https://discourse.julialang.org/t/benchmarktools-btime-breaks-my-function-arguments/103710/2 "2023-09-10T00:50:05Z")

</div>

One thing `@btime` does is run the call repeatedly, so does `simulate` push any elements to `observables` or `observable_names`, what do they look like after 1 `simulate` call?

---

<div class="post-metadata">

**Author:** ![Leibniz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leibniz/32/217959_2.png) [@Leibniz](https://discourse.julialang.org/u/Leibniz)\
**Post date:** [September 10, 2023, 12:00pm UTC](https://discourse.julialang.org/t/benchmarktools-btime-breaks-my-function-arguments/103710/3 "2023-09-10T12:00:51Z")

</div>

it does change them towards the end for some print out routine. That fixes it,cheers!
