bash regex basic simplification (50% time/cpu savings)

This commit is contained in:
2021-07-18 08:57:44 +02:00
parent 8215fde89e
commit d63a340b01
2 changed files with 12 additions and 6 deletions

View File

@@ -1,4 +1,5 @@
INPUT := INPUT.txt
INPUT1 := INPUT-part1.txt
INPUT2 := INPUT-part2.txt
SHELL := /bin/bash
CFLAGS := -w -g
#CFLAGS := -w -g -pg
@@ -16,12 +17,13 @@ output:
compile: ex1-c ex2-c
ex1:
@$(TIME) ex1.bash < $(INPUT) 2>&1
@#$(TIME) ex1-c 2020 < $(INPUT) 2>&1
@$(TIME) ex1.bash < $(INPUT1) 2>&1
@$(TIME) ex1-v2.bash < $(INPUT1) 2>&1
@#$(TIME) ex1-c 2020 < $(INPUT1) 2>&1
ex2:
@$(TIME) ex2.bash < $(INPUT) 2>&1
@#$(TIME) ex1-c 30000000 < $(INPUT) 2>&1
@$(TIME) ex2.bash < $(INPUT2) 2>&1
@#$(TIME) ex1-c 30000000 < $(INPUT2) 2>&1
clean:
@rm -f ex1-c ex2-c core

View File

@@ -29,7 +29,11 @@ function buildtree {
else
if [[ ! -v MATCH[$arg] ]]; then
buildtree "$((prof+1))" "$name" "${RULE[$arg]}"
MATCH[$arg]="(${!name})"
if [[ ${!name} =~ ^.$ ]] ; then
MATCH[$arg]="${!name}"
else
MATCH[$arg]="(${!name})"
fi
fi
res+=${MATCH[$arg]}
fi