From dadde72a4c914ecfc81583ff8aec57b91c56ec4a Mon Sep 17 00:00:00 2001 From: thurinj Date: Wed, 27 Nov 2024 12:34:52 +1100 Subject: [PATCH] Optimized C code by moving a variable outside of a loop. It seems that the repeated access to `sources(isrc,ig)` causes a slow-down that can be easily avoided by caching the source as: ```python3 double source_val = sources (isrc, ig) ``` From local test on an M1 mac, this yield a speedup of about ~1.18. Changed variable name for consistency --- mtuq/misfit/waveform/c_ext_L2.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mtuq/misfit/waveform/c_ext_L2.c b/mtuq/misfit/waveform/c_ext_L2.c index cbc6f7245..f1f43518c 100644 --- a/mtuq/misfit/waveform/c_ext_L2.c +++ b/mtuq/misfit/waveform/c_ext_L2.c @@ -209,8 +209,9 @@ static PyObject *misfit(PyObject *self, PyObject *args) { // Sum cross-correlations of all components being considered for (ig=0; ig