Skip to content

Instantly share code, notes, and snippets.

@JeffBezanson
Last active August 29, 2015 13:58
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 JeffBezanson/10416535 to your computer and use it in GitHub Desktop.
Save JeffBezanson/10416535 to your computer and use it in GitHub Desktop.
function dispatchratio(D, M::Module, expor, recur)
nspec = 0
nGFspec = 0
for name in names(M,!expor)
if isdefined(M, name)
F = eval(M, name)
if isa(F,Union(Function,DataType))
if isgeneric(F)
if !haskey(D,F)
positions = IntSet()
m = methods(F).defs
while m !== ()
for i = 1:length(m.sig)
x = m.sig[i]
if x!=Any && x!=Vararg{Any}
nspec += 1
push!(positions, i)
end
end
m = m.next
end
nGFspec += length(positions)
end
D[F] = length(methods(F))
else
D[F] = 0
end
elseif recur && isa(F,Module) && F !== M && F !== Main && F !== Base
a, b = dispatchratio(D, F, expor, recur)
nspec += a
nGFspec += b
end
end
end
nspec, nGFspec
end
for expor in (true,false), justbase in (true,false)
DR = ObjectIdDict()
ns,nGF = dispatchratio(DR, Base, expor, !justbase)
N = length(DR)
nm = sum(values(DR))
print(justbase ? "Just Base" : "Everything")
println(expor ? ", Exported" : ", Everything")
println("N = ", N)
println("DR = ", nm/N) #mean(values(DR)))
println("CR = ", sum(x->x*x, values(DR)) / nm)
println("DoS = ", ns / nm, " (N = $nm)")
println("DoS_G,avg = ", nGF/N)
println()
end
#=
Just Base, Exported
N = 1132
DR = 6.083922261484099
CR = 52.70204733555975
DoS = 1.5407289095397125 (N = 6887)
DoS_G,avg = 1.3798586572438163
Everything, Exported
N = 1273
DR = 5.644933228593873
CR = 50.66490397996103
DoS = 1.593932646813248 (N = 7186)
DoS_G,avg = 1.4650432050274942
Just Base, Everything
N = 1899
DR = 4.256450763559768
CR = 45.5020413212916
DoS = 1.5653841395521464 (N = 8083)
DoS_G,avg = 1.430753027909426
Everything, Everything
N = 2971
DR = 3.4153483675530123
CR = 36.9341677343057
DoS = 1.681482211491081 (N = 10147)
DoS_G,avg = 1.5610905419050825
Base.Operators:
N = 47
DR = 28.127659574468087
CR = 78.05748865355523
Base.Operators plus convert:
N = 48
DR = 36.145833333333336
CR = 157.78731988472623
=#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment