Skip to content

Instantly share code, notes, and snippets.

@jsams
Created April 16, 2018 22:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsams/7ea9e421b6dff765e89289f8fc617f60 to your computer and use it in GitHub Desktop.
Save jsams/7ea9e421b6dff765e89289f8fc617f60 to your computer and use it in GitHub Desktop.
benchmark hiding function arguments?
using BenchmarkTools
function _test(N, prods, pos_prods, maxseen)
z = 0
for i in 1:N
neg = setdiff(prods, pos_prods[i])
z += rand(1:maxseen)
end
return z
end
function _test2(N, prods, pos_prods, maxseen)
z = 0
for i in 1:N
neg = pos_prods[i]
z += rand(1:maxseen)
end
return z
end
function test_intset_setdiff(N, S; maxseen=round(Integer, sqrt(S)))
prods = IntSet(1:S)
pos_prods = [IntSet(rand(1:S, rand(1:maxseen))) for _ in 1:N]
_test(N, prods, pos_prods, maxseen)
_test2(N, prods, pos_prods, maxseen)
@benchmark _test(N, prods, pos_prods, maxseen)
@benchmark _test2(N, prods, pos_prods, maxseen)
return setbench, purerand
end
b = test_intset_setdiff(2000, 3000)
#julia> b = test_intset_setdiff(2000, 3000)
#ERROR: UndefVarError: N not defined
#Stacktrace:
# [1] ##core#664() at /home/james/.julia/v0.6/BenchmarkTools/src/execution.jl:316
# [2] ##sample#665(::BenchmarkTools.Parameters) at /home/james/.julia/v0.6/BenchmarkTools/src/execution.jl:322
# [3] #_run#4(::Bool, ::String, ::Array{Any,1}, ::Function, ::BenchmarkTools.Benchmark{Symbol("##benchmark#663")}, ::BenchmarkTools.Parameters) at /home/james/.julia/v0.6/BenchmarkTools/src/execution.jl:350
# [4] (::BenchmarkTools.#kw##_run)(::Array{Any,1}, ::BenchmarkTools.#_run, ::BenchmarkTools.Benchmark{Symbol("##benchmark#663")}, ::BenchmarkTools.Parameters) at ./<missing>:0
# [5] anonymous at ./<missing>:?
# [6] #run_result#19(::Array{Any,1}, ::Function, ::BenchmarkTools.Benchmark{Symbol("##benchmark#663")}, ::BenchmarkTools.Parameters) at /home/james/.julia/v0.6/BenchmarkTools/src/execution.jl:44
# [7] (::BenchmarkTools.#kw##run_result)(::Array{Any,1}, ::BenchmarkTools.#run_result, ::BenchmarkTools.Benchmark{Symbol("##benchmark#663")}, ::BenchmarkTools.Parameters) at ./<missing>:0
# [8] #run#21(::Array{Any,1}, ::Function, ::BenchmarkTools.Benchmark{Symbol("##benchmark#663")}, ::BenchmarkTools.Parameters) at /home/james/.julia/v0.6/BenchmarkTools/src/execution.jl:67
# [9] (::Base.#kw##run)(::Array{Any,1}, ::Base.#run, ::BenchmarkTools.Benchmark{Symbol("##benchmark#663")}, ::BenchmarkTools.Parameters) at ./<missing>:0 (repeats 2 times)
# [10] macro expansion at /home/james/.julia/v0.6/BenchmarkTools/src/execution.jl:234 [inlined]
# [11] #test_intset_setdiff#1(::Int64, ::Function, ::Int64, ::Int64) at ./REPL[4]:6
# [12] test_intset_setdiff(::Int64, ::Int64) at ./REPL[4]:2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment