Benchmark specialized method against general method


#1

Julia always uses the most specialized method. For a specific occasion, is there a way to force it to instead use the method that is one level more general? Or, more generally, any specific more general method?

For example, with the following definition,

julia>  f(x) = x
julia>  f(x::Int) = 2*x

I’d still like to be able to do something like f(Any(2)), and have 2 returned. In some cases, I am able to use type conversions to get to the more general method, but there is no concrete Any type, so that doesn’t work generally.

The purpose of this is profiling: I’d like to profile a new more specialized method against the older, slightly more general method. Preferably without copying the code for the older general method to a new name.


#2
julia> invoke(f,Tuple{Any},2)
2


Eliminite overhead of "invoke" in benchmark