From c1d4257778c5c28620228225dc2dfc18472075d9 Mon Sep 17 00:00:00 2001 From: Hongyang Zhou Date: Wed, 11 Feb 2026 14:33:06 -0500 Subject: [PATCH 1/2] doc: add performance comparison table --- docs/examples/features/demo_hybrid.jl | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/docs/examples/features/demo_hybrid.jl b/docs/examples/features/demo_hybrid.jl index 104df29aa..d9c81b265 100644 --- a/docs/examples/features/demo_hybrid.jl +++ b/docs/examples/features/demo_hybrid.jl @@ -11,7 +11,7 @@ import DisplayAs #hide using TestParticle, OrdinaryDiffEq, StaticArrays import TestParticle as TP -using LinearAlgebra, Random +using LinearAlgebra, Random, Printf, Markdown using CairoMakie CairoMakie.activate!(type = "png") #hide @@ -62,7 +62,8 @@ tspan = (0.0, 30 * T_gyro) param_fo = prepare(E_field, B_field; species = Proton) prob_fo = ODEProblem(trace, u0, tspan, param_fo) -sol_fo = solve(prob_fo, Vern9()) +stats_fo = @timed solve(prob_fo, Vern9(); save_everystep = true) +sol_fo = stats_fo.value; ## Verify trapping: z should oscillate, not diverge z_fo = [u[3] for u in sol_fo.u] @@ -79,7 +80,8 @@ stateinit_gc, param_gc = TP.prepare_gc( u0, bottle_E_static, bottle_B_static; species = Proton ) prob_gc = ODEProblem(trace_gc!, stateinit_gc, tspan, param_gc) -sol_gc = solve(prob_gc, Vern9()); +stats_gc = @timed solve(prob_gc, Vern9()) +sol_gc = stats_gc.value; # ## Step 3: Hybrid Solver # @@ -100,7 +102,8 @@ alg = AdaptiveHybrid(; Random.seed!(1234) ## Set verbose = true to see the dynamic switching -sol = TP.solve(TraceHybridProblem(u0, tspan, p), alg; verbose = false)[1]; +stats_hybrid = @timed TP.solve(TraceHybridProblem(u0, tspan, p), alg; verbose = false) +sol = stats_hybrid.value[1]; # ## Step 4: Compute Adiabaticity # @@ -251,3 +254,15 @@ Legend(f[3, 1:4], ax_ts; orientation = :horizontal) rowsize!(f.layout, 1, Relative(0.55)) f = DisplayAs.PNG(f) #hide + +# ## Performance Comparison +# +# Finally, we compare the execution time and memory allocations of the three solvers. + +io = IOBuffer() #hide +println(io, "| Solver | Time | Allocations |") #hide +println(io, "| :--- | :--- | :--- |") #hide +Printf.@printf(io, "| Full Orbit | %.4e s | %.4e bytes |\n", stats_fo.time, stats_fo.bytes) #hide +Printf.@printf(io, "| Guiding Center | %.4e s | %.4e bytes |\n", stats_gc.time, stats_gc.bytes) #hide +Printf.@printf(io, "| Hybrid | %.4e s | %.4e bytes |\n", stats_hybrid.time, stats_hybrid.bytes) #hide +Markdown.parse(String(take!(io))) #hide From 205b983af4ee8ab1ec7a67d35003ebbb728d01d6 Mon Sep 17 00:00:00 2001 From: Hongyang Zhou Date: Wed, 11 Feb 2026 14:52:44 -0500 Subject: [PATCH 2/2] Format table display --- docs/examples/features/demo_hybrid.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/examples/features/demo_hybrid.jl b/docs/examples/features/demo_hybrid.jl index d9c81b265..1e6bbd923 100644 --- a/docs/examples/features/demo_hybrid.jl +++ b/docs/examples/features/demo_hybrid.jl @@ -260,9 +260,9 @@ f = DisplayAs.PNG(f) #hide # Finally, we compare the execution time and memory allocations of the three solvers. io = IOBuffer() #hide -println(io, "| Solver | Time | Allocations |") #hide +println(io, "| Solver | Time (s) | Allocations (bytes) |") #hide println(io, "| :--- | :--- | :--- |") #hide -Printf.@printf(io, "| Full Orbit | %.4e s | %.4e bytes |\n", stats_fo.time, stats_fo.bytes) #hide -Printf.@printf(io, "| Guiding Center | %.4e s | %.4e bytes |\n", stats_gc.time, stats_gc.bytes) #hide -Printf.@printf(io, "| Hybrid | %.4e s | %.4e bytes |\n", stats_hybrid.time, stats_hybrid.bytes) #hide +Printf.@printf(io, "| Full Orbit | %.2e | %.2e |\n", stats_fo.time, stats_fo.bytes) #hide +Printf.@printf(io, "| Guiding Center | %.2e | %.2e |\n", stats_gc.time, stats_gc.bytes) #hide +Printf.@printf(io, "| Hybrid | %.2e | %.2e |\n", stats_hybrid.time, stats_hybrid.bytes) #hide Markdown.parse(String(take!(io))) #hide