Created
May 11, 2016 22:27
-
-
Save ivirshup/976c5dfd3d96aacbde6004327e2b3cc7 to your computer and use it in GitHub Desktop.
`counter` function slowdown using parameterized methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
julia> import Base.push! | |
julia> import Base.getindex | |
julia> type Accumulator{T, V<:Number} | |
map::Dict{T,V} | |
end | |
julia> Accumulator{T,V<:Number}(::Type{T}, ::Type{V}) = Accumulator{T,V}(Dict{T,V}()) | |
Accumulator{T,V<:Number} | |
julia> counter(T::Type) = Accumulator(T,Int) | |
counter (generic function with 1 method) | |
julia> function counter{T}(seq::AbstractArray{T}) | |
ct = counter(T) | |
for x in seq | |
push!(ct, x) | |
end | |
return ct | |
end | |
counter (generic function with 2 methods) | |
julia> data = filter!(x->isa(x,Function), map(eval, names(Base))); | |
julia> data = convert(Array{Function,1}, data); | |
julia> getindex(ct, x) = get(ct.map, x, zero(Int)) | |
getindex (generic function with 173 methods) | |
julia> push!(ct::Accumulator, x, a) = (ct.map[x] = ct[x] + a) | |
push! (generic function with 19 methods) | |
julia> push!(ct::Accumulator, x) = push!(ct, x, one(Int)) | |
push! (generic function with 20 methods) | |
julia> @profile @time counter(data) | |
0.125531 seconds (82.06 k allocations: 3.443 MB, 6.79% gc time) | |
Accumulator{Function,Int64}(Dict{Function,Int64}(Pair{Function,Int64}(find,1),Pair{Function,Int64}(middle,1),Pair{Function,Int64}(launch,1),Pair{Function,Int64}(givens,1),Pair{Function,Int64}(@ip_str,1),Pair{Function,Int64}(object_id,1),Pair{Function,Int64}(readandwrite,1),Pair{Function,Int64}(prevind,1),Pair{Function,Int64}(hist2d,1),Pair{Function,Int64}(resize!,1)…)) | |
julia> Profile.print(format=:flat) | |
Count File Line Function | |
108 ./REPL.jl 62 eval_user_input(::Any, ::Base.REPL.REPLBackend) | |
1 ./REPL.jl 65 eval_user_input(::Any, ::Base.REPL.REPLBackend) | |
43 ./REPL[6] 4 counter(::Array{Function,1}) | |
4 ./REPL[9] 1 getindex(::Accumulator{Function,Int64}, ::Fun... | |
108 ./boot.jl 230 eval(::Module, ::Any) | |
26 ./dict.jl 705 setindex!(::Dict{Function,Int64}, ::Int64, ::... | |
5 ./dict.jl 711 setindex!(::Dict{Function,Int64}, ::Int64, ::... | |
109 ./event.jl 46 (::Base.REPL.##1#2{Base.REPL.REPLBackend})() | |
6 ./grisu.jl 46 grisu(::Float64, ::Int64, ::Int64, ::Array{UI... | |
5 ./grisu/fastfixed.jl 233 fastfixedtoa(::Float64, ::Int64, ::Int64, ::A... | |
1 ./grisu/fastfixed.jl 243 fastfixedtoa(::Float64, ::Int64, ::Int64, ::A... | |
4 ./grisu/fastfixed.jl 44 filldigits32(::UInt32, ::Array{UInt8,1}, ::Int64) | |
1 ./grisu/fastfixed.jl 45 filldigits32(::UInt32, ::Array{UInt8,1}, ::Int64) | |
1 ./grisu/fastfixed.jl 119 fillfractionals(::UInt64, ::Int32, ::Int64, :... | |
1 ./inference.jl 507 (::Core.Inference.##114#115)(::Type{T}, ::Cor... | |
1 ./inference.jl 145 Core.Inference.InferenceState(::LambdaInfo, :... | |
1 ./inference.jl 3170 _getfield_elim_pass!(::Expr, ::Core.Inference... | |
1 ./inference.jl 3172 _getfield_elim_pass!(::Expr, ::Core.Inference... | |
2 ./inference.jl 985 abstract_call(::Any, ::Array{Any,1}, ::Array{... | |
5 ./inference.jl 1020 abstract_call(::Any, ::Array{Any,1}, ::Array{... | |
86 ./inference.jl 1027 abstract_call(::Any, ::Array{Any,1}, ::Array{... | |
2 ./inference.jl 755 abstract_call_gf_by_type(::Any, ::Any, ::Core... | |
84 ./inference.jl 856 abstract_call_gf_by_type(::Any, ::Any, ::Core... | |
113 ./inference.jl 1082 abstract_eval(::Any, ::Array{Any,1}, ::Core.I... | |
6 ./inference.jl 1093 abstract_eval(::Any, ::Array{Any,1}, ::Core.I... | |
20 ./inference.jl 1031 abstract_eval_call(::Expr, ::Array{Any,1}, ::... | |
93 ./inference.jl 1057 abstract_eval_call(::Expr, ::Array{Any,1}, ::... | |
1 ./inference.jl 1176 abstract_eval_constant(::Any) | |
1 ./inference.jl 1181 abstract_eval_global(::Module, ::Symbol) | |
26 ./inference.jl 1211 abstract_interpret(::Any, ::Array{Any,1}, ::C... | |
21 ./inference.jl 1219 abstract_interpret(::Any, ::Array{Any,1}, ::C... | |
1 ./inference.jl 3271 alloc_elim_pass!(::LambdaInfo, ::Core.Inferen... | |
1 ./inference.jl 3295 alloc_elim_pass!(::LambdaInfo, ::Core.Inferen... | |
1 ./inference.jl 651 builtin_tfunction(::Any, ::Array{Any,1}, ::Co... | |
1 ./inference.jl 705 builtin_tfunction(::Any, ::Array{Any,1}, ::Co... | |
1 ./inference.jl 2199 effect_free(::Any, ::Core.Inference.Inference... | |
1 ./inference.jl 2159 exprtype(::Any, ::Core.Inference.InferenceState) | |
1 ./inference.jl 3083 find_sa_vars(::LambdaInfo) | |
1 ./inference.jl 1363 find_ssavalue_uses(::Array{Any,1}) | |
2 ./inference.jl 1391 find_ssavalue_uses(::Any, ::Array{Core.Infere... | |
3 ./inference.jl 1911 finish(::Core.Inference.InferenceState) | |
19 ./inference.jl 1920 finish(::Core.Inference.InferenceState) | |
2 ./inference.jl 1923 finish(::Core.Inference.InferenceState) | |
2 ./inference.jl 1924 finish(::Core.Inference.InferenceState) | |
2 ./inference.jl 3164 getfield_elim_pass!(::LambdaInfo, ::Core.Infe... | |
1 ./inference.jl 477 getfield_tfunc(::Any, ::Core.Inference.Const) | |
7 ./inference.jl 2329 inlineable(::Any, ::Any, ::Expr, ::Array{Any,... | |
1 ./inference.jl 2494 inlineable(::Any, ::Any, ::Expr, ::Array{Any,... | |
1 ./inference.jl 2572 inlineable(::Any, ::Any, ::Expr, ::Array{Any,... | |
1 ./inference.jl 2586 inlineable(::Any, ::Any, ::Expr, ::Array{Any,... | |
2 ./inference.jl 2734 inlineable(::Any, ::Any, ::Expr, ::Array{Any,... | |
19 ./inference.jl 2805 inlining_pass!(::LambdaInfo, ::Core.Inference... | |
7 ./inference.jl 2828 inlining_pass(::Expr, ::Core.Inference.Infere... | |
35 ./inference.jl 2857 inlining_pass(::Expr, ::Core.Inference.Infere... | |
12 ./inference.jl 2931 inlining_pass(::Expr, ::Core.Inference.Infere... | |
1 ./inference.jl 3003 is_known_call(::Expr, ::Function, ::Core.Infe... | |
5 ./inference.jl 940 pure_eval_call(::Any, ::Any, ::Type{T}, ::Cor... | |
3 ./inference.jl 2031 type_annotate!(::LambdaInfo, ::Array{Any,1}, ... | |
2 ./inference.jl 1437 typeinf_edge(::Method, ::Any, ::SimpleVector,... | |
1 ./inference.jl 1513 typeinf_edge(::Method, ::Any, ::SimpleVector,... | |
121 ./inference.jl 1532 typeinf_edge(::Method, ::Any, ::SimpleVector,... | |
84 ./inference.jl 1537 typeinf_edge(::Method, ::Any, ::SimpleVector,... | |
40 ./inference.jl 1552 typeinf_ext(::LambdaInfo) | |
48 ./inference.jl 1655 typeinf_frame(::Core.Inference.InferenceState) | |
46 ./inference.jl 1732 typeinf_frame(::Core.Inference.InferenceState) | |
1 ./inference.jl 1777 typeinf_frame(::Core.Inference.InferenceState) | |
14 ./inference.jl 1833 typeinf_frame(::Core.Inference.InferenceState) | |
81 ./inference.jl 1580 typeinf_loop(::Core.Inference.InferenceState) | |
28 ./inference.jl 1598 typeinf_loop(::Core.Inference.InferenceState) | |
12 ./inference.jl 1612 typeinf_loop(::Core.Inference.InferenceState) | |
5 ./printf.jl 784 fix_dec(::Base.TTY, ::Float64, ::String, ::In... | |
6 ./printf.jl 938 fix_dec(::Float64, ::Int64) | |
1 ./printf.jl 190 print_fixed(::Base.TTY, ::Int64, ::Int32, ::I... | |
108 ./profile.jl 16 anonymous | |
13 ./reflection.jl 199 _methods_by_ftype(::Any, ::Int64) | |
14 ./util.jl 112 time_print(::UInt64, ::Int64, ::Int64, ::Int64) | |
8 ./util.jl 119 time_print(::UInt64, ::Int64, ::Int64, ::Int64) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment