I need a `sortperm!`

function which returns the number of comparisons actually performed to sort an array. I thought I could do this by intercepting and counting the calls to `isless`

.

After a few trials I identified two possible solutions, implemented in the `mysortperm1!`

and `mysortperm2!`

functions shown below. Questions are:

- why
`mysortperm1!`

is much slower than`mysortperm2!`

? - is there a better (i.e. faster) way to solve this problem?

```
function mysortperm1!(p, v)
counter = 0
sortperm!(p, v, lt=(a,b) -> (counter += 1; a < b))
return counter
end
function mysortperm2!(p, v)
counter = [0]
sortperm!(p, v, lt=(a,b) -> (counter[1] += 1; a < b))
return counter[1]
end
using BenchmarkTools
n = 100_000
v = rand(n);
p = zeros(Int, length(v));
@btime sortperm!(p, v);
@btime mysortperm1!(p, v)
@btime mysortperm2!(p, v)
```

Thanks