# Force calling the generic for benchmarking

**URL:** <https://discourse.julialang.org/t/force-calling-the-generic-for-benchmarking/56009>\
**Category:** Performance\
**Created:** [February 25, 2021, 11:49am UTC](https://discourse.julialang.org/t/force-calling-the-generic-for-benchmarking/56009 "2021-02-25T11:49:02Z")\
**Posts on this page:** 2\
**Page:** 1

<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:** [February 25, 2021, 11:49am UTC](https://discourse.julialang.org/t/force-calling-the-generic-for-benchmarking/56009/1 "2021-02-25T11:49:02Z")

</div>

Consider the following dummy example:

```julia
function f(x)
    println("We called the generic")
    prod(x)
end
function f(x::Real)
    println("We called the method")
    x
end

# Some checks: 
f(1)
f([1 2])

```

How can I force `f(1)` to run the generic, to compare it’s performance w.r.t the specialized method ? (using e.g. `@btime`) ?

I’d like to benchmark my generic function f against the specialized methods to be sure that they are worth it: they return the same thing as the generic, just written in an hopefully faster way. If the time gain is not effective, i might just remove these methods and simplify my package.

---

<div class="post-metadata">

**Author:** ![sostock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sostock/32/5546_2.png) [@sostock](https://discourse.julialang.org/u/sostock)\
**Post date:** [February 25, 2021, 12:08pm UTC](https://discourse.julialang.org/t/force-calling-the-generic-for-benchmarking/56009/2 "2021-02-25T12:08:36Z")

</div>

You can use the `invoke` function for this, i.e.,

```julia
invoke(f, Tuple{Any}, 1)

```

will call the generic `f(::Any)` method with the argument `1`. In Julia 1.7 you will be able to use the simpler syntax `Base.@invoke f(1::Any)`.
