benducke / Network-reconstruction-tools-for-GRASS-GIS

Node-based network model generator for GRASS GIS 7.x (and QGIS 3.x)
GNU General Public License v3.0
4 stars 1 forks source link

Add BASHisms to speed up arithmetics and array operations when possible #50

Open benducke opened 2 months ago

benducke commented 2 months ago

Currently, all scripts are written to run on the ancient Bourne Shell for maximum backward compatibility. However, on many modern systems, the 'sh' executable is just a link to 'bash' which is fully Bourne Shell compatible.

So in the most frequent use case, we should actually have full BASH capabilities available, even if using "/bin/sh" as interpreter.

BASH has some built-in commands for arithmetics and data structures that can tremendously speed up repetitive operations. Currently, such operations are a huge bottleneck whenever they involve calling an external command, such as 'expr'.

E.,g., an easy speed-up of loop integer increments for all BASH-capable (i.e. pretty much all modern) systems looks like this (using internal 'let' instead of external 'expr'):

if [ -n $BASH_VERSION ] ; then
    let counter=${counter}+1
else
    counter=`"${EXPR}" ${counter} + 1`
fi