Speed measurement
Here we will compare the speed of plotting UnfoldMakie with MNE (Python) and EEGLAB (MATLAB).
Three cases are measured:
- Single topoplot
- Topoplot series with 50 topoplots
- Topoplott animation with 50 timestamps
Note that the results of benchmarking on your computer and on Github may differ.
using UnfoldMakie
using TopoPlots
using PyMNE
using PythonPlot
using BenchmarkTools
using Observables
using CairoMakie
Precompiling PythonPlot...
3010.2 ms ✓ PythonPlot
1 dependency successfully precompiled in 3 seconds. 57 already precompiled.
Data input
dat, positions = TopoPlots.example_data()
df = UnfoldMakie.eeg_array_to_dataframe(dat[:, :, 1], string.(1:length(positions)));
Topoplots
UnfoldMakie.jl
@benchmark plot_topoplot(dat[:, 320, 1]; positions = positions)
BenchmarkTools.Trial: 135 samples with 1 evaluation per sample.
Range (min … max): 32.499 ms … 376.404 ms ┊ GC (min … max): 0.00% … 89.89%
Time (median): 34.396 ms ┊ GC (median): 0.00%
Time (mean ± σ): 37.171 ms ± 29.458 ms ┊ GC (mean ± σ): 6.74% ± 7.74%
▅█▂▂▆ ▄
▇▅█▆██████▇█▆▃▁▅▄▅▁▆▆▅▁▄▁▁▁▁▁▁▃▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▃ ▃
32.5 ms Histogram: frequency by time 45.9 ms <
Memory estimate: 9.08 MiB, allocs estimate: 138336.
UnfoldMakie.jl with DelaunayMesh
@benchmark plot_topoplot(
dat[:, 320, 1];
positions = positions,
topo_interpolation = (; interpolation = DelaunayMesh()),
)
BenchmarkTools.Trial: 144 samples with 1 evaluation per sample.
Range (min … max): 32.458 ms … 65.008 ms ┊ GC (min … max): 0.00% … 0.00%
Time (median): 33.998 ms ┊ GC (median): 0.00%
Time (mean ± σ): 34.888 ms ± 3.282 ms ┊ GC (mean ± σ): 0.00% ± 0.00%
▇█▇ ▁ ▁
▅████▇▇█▆▆▃█▆▅▄▆▃▄▃▄▃▁▁▃▁▁▁▁▃▁▁▁▁▃▁▃▁▁▁▁▁▃▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▃ ▃
32.5 ms Histogram: frequency by time 47.9 ms <
Memory estimate: 9.08 MiB, allocs estimate: 138343.
MNE
posmat = collect(reduce(hcat, [[p[1], p[2]] for p in positions])')
pypos = Py(posmat).to_numpy()
pydat = Py(dat[:, 320, 1])
@benchmark begin
f = PythonPlot.figure()
PyMNE.viz.plot_topomap(
pydat,
pypos,
sphere = 1.1,
extrapolate = "box",
cmap = "RdBu_r",
sensors = false,
contours = 6,
)
f.show()
end
BenchmarkTools.Trial: 301 samples with 1 evaluation per sample.
Range (min … max): 11.951 ms … 642.688 ms ┊ GC (min … max): 0.00% … 0.00%
Time (median): 12.163 ms ┊ GC (median): 0.00%
Time (mean ± σ): 16.605 ms ± 48.530 ms ┊ GC (mean ± σ): 0.00% ± 0.00%
██▂ ▁▁
███▇▆▅▄▁▄██▇▆▄▆▁▄▁▄▅▄▁▁▁▁▁▄▄▁▁▁▁▁▄▄▁▁▁▁▁▄▁▁▄▁▄▁▁▁▁▁▁▁▁▁▁▁▁▁▄ ▆
12 ms Histogram: log(frequency) by time 23.3 ms <
Memory estimate: 4.22 KiB, allocs estimate: 130.
Topoplot series
Note that UnfoldMakie and MNE have different defaults for displaying topoplot series. UnfoldMakie in plot_topoplot
averages over time samples. MNE in plot_topopmap
displays single samples without averaging.
UnfoldMakie.jl
@benchmark begin
plot_topoplotseries(
df;
bin_num = 50,
positions = positions,
axis = (; xlabel = "Time windows [s]"),
)
end
BenchmarkTools.Trial: 3 samples with 1 evaluation per sample.
Range (min … max): 1.884 s … 1.982 s ┊ GC (min … max): 0.00% … 0.00%
Time (median): 1.908 s ┊ GC (median): 0.00%
Time (mean ± σ): 1.924 s ± 50.978 ms ┊ GC (mean ± σ): 0.00% ± 0.00%
█ █ █
█▁▁▁▁▁▁▁▁▁▁▁▁▁█▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█ ▁
1.88 s Histogram: frequency by time 1.98 s <
Memory estimate: 397.79 MiB, allocs estimate: 5726659.
MNE
easycap_montage = PyMNE.channels.make_standard_montage("standard_1020")
ch_names = pyconvert(Vector{String}, easycap_montage.ch_names)[1:64]
info = PyMNE.create_info(PyList(ch_names), ch_types = "eeg", sfreq = 1)
info.set_montage(easycap_montage)
simulated_epochs = PyMNE.EvokedArray(Py(dat[:, :, 1]), info)
@benchmark simulated_epochs.plot_topomap(1:50)
BenchmarkTools.Trial: 6 samples with 1 evaluation per sample.
Range (min … max): 686.867 ms … 2.055 s ┊ GC (min … max): 0.00% … 0.00%
Time (median): 715.336 ms ┊ GC (median): 0.00%
Time (mean ± σ): 931.103 ms ± 550.896 ms ┊ GC (mean ± σ): 0.00% ± 0.00%
▃█
██▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▇ ▁
687 ms Histogram: frequency by time 2.06 s <
Memory estimate: 3.20 KiB, allocs estimate: 107.
MATLAB
Running MATLAB on a GitHub Action is not easy. So we benchmarked three consecutive executions (on a screenshot) on a server with an AMD EPYC 7452 32-core processor. Note that Github and the server we used for MATLAB benchmarking are two different computers, which can give different timing results.

Animation
The main advantage of Julia is the speed with which the figures are updated.
timestamps = range(1, 50, step = 1)
framerate = 50
50
UnfoldMakie with .gif
@benchmark begin
f = Makie.Figure()
dat_obs = Observable(dat[:, 1, 1])
plot_topoplot!(f[1, 1], dat_obs, positions = positions)
record(f, "topoplot_animation_UM.gif", timestamps; framerate = framerate) do t
dat_obs[] = @view(dat[:, t, 1])
end
end
BenchmarkTools.Trial: 2 samples with 1 evaluation per sample.
Range (min … max): 3.886 s … 3.971 s ┊ GC (min … max): 0.00% … 0.00%
Time (median): 3.929 s ┊ GC (median): 0.00%
Time (mean ± σ): 3.929 s ± 60.008 ms ┊ GC (mean ± σ): 0.00% ± 0.00%
█ █
█▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█ ▁
3.89 s Histogram: frequency by time 3.97 s <
Memory estimate: 680.16 MiB, allocs estimate: 944276.
MNE with .gif
@benchmark begin
fig, anim = simulated_epochs.animate_topomap(
times = Py(timestamps),
frame_rate = framerate,
blit = false,
image_interp = "cubic", # same as CloughTocher
)
anim.save("topomap_animation_mne.gif", writer = "ffmpeg", fps = framerate)
end
BenchmarkTools.Trial: 1 sample with 1 evaluation per sample.
Single result which took 8.941 s (0.00% GC) to evaluate,
with a memory estimate of 4.13 KiB, over 154 allocations.
Note, that due to some bugs in (probably) PythonCall
topoplot is black and white.
This page was generated using Literate.jl.