diff --git a/base/exports.jl b/base/exports.jl index 24b1ddb52f5e73..88933dad882caf 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -993,7 +993,6 @@ export @timev, @elapsed, @allocated, - @time_imports, # tasks @sync, diff --git a/base/timing.jl b/base/timing.jl index a505db0f82af26..7af6f038ba6ea0 100644 --- a/base/timing.jl +++ b/base/timing.jl @@ -371,45 +371,3 @@ macro timed(ex) (value=val, time=elapsedtime/1e9, bytes=diff.allocd, gctime=diff.total_time/1e9, gcstats=diff) end end - -""" - @time_imports - -A macro to execute an expression and produce a report of any time spent importing packages and their -dependencies. - -If a package's dependencies have already been imported either globally or by another dependency they will -not appear under that package and the package will accurately report a faster load time than if it were to -be loaded in isolation. - -```julia-repl -julia> @time_imports using CSV - 3.5 ms ┌ IteratorInterfaceExtensions - 27.4 ms ┌ TableTraits - 614.0 ms ┌ SentinelArrays - 138.6 ms ┌ Parsers - 2.7 ms ┌ DataValueInterfaces - 3.4 ms ┌ DataAPI - 59.0 ms ┌ WeakRefStrings - 35.4 ms ┌ Tables - 49.5 ms ┌ PooledArrays - 972.1 ms CSV -``` - -!!! note - During the load process a package sequentially imports where necessary all of its dependencies, not just - its direct dependencies. That is also true for the dependencies themselves so nested importing will likely - occur, but not always. Therefore the nesting shown in this output report is not equivalent to the dependency - tree, but does indicate where import time has accumulated. - -""" -macro time_imports(ex) - quote - try - LOAD_TIMING[Threads.threadid()] += 1 - $(esc(ex)) - finally - LOAD_TIMING[Threads.threadid()] -= 1 - end - end -end diff --git a/stdlib/InteractiveUtils/docs/src/index.md b/stdlib/InteractiveUtils/docs/src/index.md index 71499744ecb1d2..9ad4b5a7cea80b 100644 --- a/stdlib/InteractiveUtils/docs/src/index.md +++ b/stdlib/InteractiveUtils/docs/src/index.md @@ -26,5 +26,6 @@ InteractiveUtils.code_llvm InteractiveUtils.@code_llvm InteractiveUtils.code_native InteractiveUtils.@code_native +InteractiveUtils.@time_imports InteractiveUtils.clipboard ``` diff --git a/stdlib/InteractiveUtils/src/InteractiveUtils.jl b/stdlib/InteractiveUtils/src/InteractiveUtils.jl index 6f8ba9ea0b0802..6eb75e8c0b685c 100644 --- a/stdlib/InteractiveUtils/src/InteractiveUtils.jl +++ b/stdlib/InteractiveUtils/src/InteractiveUtils.jl @@ -6,7 +6,7 @@ Base.Experimental.@optlevel 1 export apropos, edit, less, code_warntype, code_llvm, code_native, methodswith, varinfo, versioninfo, subtypes, supertypes, @which, @edit, @less, @functionloc, @code_warntype, - @code_typed, @code_lowered, @code_llvm, @code_native, clipboard + @code_typed, @code_lowered, @code_llvm, @code_native, @time_imports, clipboard import Base.Docs.apropos diff --git a/stdlib/InteractiveUtils/src/macros.jl b/stdlib/InteractiveUtils/src/macros.jl index 98c47f02f27071..9de51870353e57 100644 --- a/stdlib/InteractiveUtils/src/macros.jl +++ b/stdlib/InteractiveUtils/src/macros.jl @@ -232,6 +232,17 @@ macro code_lowered(ex0...) end end +macro time_imports(ex) + quote + try + Base.LOAD_TIMING[Threads.threadid()] += 1 + $(esc(ex)) + finally + Base.LOAD_TIMING[Threads.threadid()] -= 1 + end + end +end + """ @functionloc @@ -332,3 +343,36 @@ Set the optional keyword argument `debuginfo` by putting it before the function `debuginfo` may be one of `:source` (default) or `:none`, to specify the verbosity of code comments. """ :@code_native + +""" + @time_imports + +A macro to execute an expression and produce a report of any time spent importing packages and their +dependencies. + +If a package's dependencies have already been imported either globally or by another dependency they will +not appear under that package and the package will accurately report a faster load time than if it were to +be loaded in isolation. + +```julia-repl +julia> @time_imports using CSV + 3.5 ms ┌ IteratorInterfaceExtensions + 27.4 ms ┌ TableTraits + 614.0 ms ┌ SentinelArrays + 138.6 ms ┌ Parsers + 2.7 ms ┌ DataValueInterfaces + 3.4 ms ┌ DataAPI + 59.0 ms ┌ WeakRefStrings + 35.4 ms ┌ Tables + 49.5 ms ┌ PooledArrays + 972.1 ms CSV +``` + +!!! note + During the load process a package sequentially imports where necessary all of its dependencies, not just + its direct dependencies. That is also true for the dependencies themselves so nested importing will likely + occur, but not always. Therefore the nesting shown in this output report is not equivalent to the dependency + tree, but does indicate where import time has accumulated. + +""" +:@time_imports