From c1983f6a5892ad5e97e9e66c1b839323e53d0832 Mon Sep 17 00:00:00 2001 From: Mandar Chitre Date: Sat, 4 Jan 2025 15:03:01 +0800 Subject: [PATCH] refactor: reduce precompile time --- Project.toml | 2 +- src/SignalAnalysis.jl | 17 +++-------------- src/precompile.jl | 30 ++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 15 deletions(-) create mode 100644 src/precompile.jl diff --git a/Project.toml b/Project.toml index a5dea92..ebce39d 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "SignalAnalysis" uuid = "df1fea92-c066-49dd-8b36-eace3378ea47" authors = ["Mandar Chitre "] -version = "0.10.1" +version = "0.10.2" [deps] DSP = "717857b8-e6f2-59f4-9121-6e50c889abd2" diff --git a/src/SignalAnalysis.jl b/src/SignalAnalysis.jl index bd471ff..654c0de 100644 --- a/src/SignalAnalysis.jl +++ b/src/SignalAnalysis.jl @@ -13,7 +13,7 @@ using DocStringExtensions @reexport using Statistics @reexport using LinearAlgebra -export 𝓈, ms, Hz, kHz +export 𝓈, ms, Hz, kHz, ° const 𝓈 = Units.s @@ -34,19 +34,8 @@ end using PrecompileTools -@setup_workload begin - using Test - rng = Random.MersenneTwister(0) - include("../test/tests-core.jl") - @compile_workload begin - test_signals() - test_generate() - test_basic() - test_dsp() - test_rand() - test_array() - test_tfa() - end +@compile_workload begin + include("precompile.jl") end end # module diff --git a/src/precompile.jl b/src/precompile.jl new file mode 100644 index 0000000..c898ea9 --- /dev/null +++ b/src/precompile.jl @@ -0,0 +1,30 @@ +# toy load to force precompilation of typical use cases + +function _precompile(x) + length(x), size(x), nframes(x), framerate(x), nchannels(x), isanalytic(x) + domain(x), time([1,2,3], x), time(1:3, x), samples(x), analytic(x) + toframe(0.2𝓈, x), toframe([0.2𝓈, 201ms], x), toframe((0.2𝓈, 201ms), x), toframe(0.2:0.201s, x) + padded(x, (10, 5); delay=1), samerateas(x) + collect(partition(x, 5)) + ifrequency(x), energy(x), meantime(x), rmsduration(x), meanfrequency(x), rmsbandwidth(x) + removedc(x), removedc!(x) + hb = rand(eltype(x), 127) + goertzel(x, 1000.0), filt(hb, x), filtfilt(hb, x) + upconvert(downconvert(x, 4, 2000.0), 4, 2000.0) + if x isa AbstractVector + mfilter(x[1:10], x), findsignal(x[1:10], x) + delay(x, 0.5), delay(x, 1), delay!(x, 1), delay!(x, 0.5), delay!(x, 0.5𝓈), delay(x, 0.5𝓈) + end +end + +for T ∈ (Float64, Float32, ComplexF64, ComplexF32) + _precompile(signal(randn(T, 200), 1000)) + _precompile(signal(randn(T, (200, 2)), 1000)) +end + +cw(1000, 0.1, 44100) +cw(1000.0, 0.1, 44100.0) +chirp(100.0, 5000.0, 0.1, 44100.0) +chirp(100, 5000, 0.1, 44100) +mseq(3), gmseq(3) +fir(127, 100.0, 5000.0; fs=44100.0)