Skip to content

Instantly share code, notes, and snippets.

@jsams

jsams/intset.jl

Created Apr 16, 2018
Embed
What would you like to do?
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