Difference between revisions of "Profiling"

From Apertium
Jump to navigation Jump to search
(Created page with "To "profile" a language pair to see which part of the pipeline is the slowest, run each step one at a time. Here's a helper that will do that for you: <pre> apertium_time_mod...")
 
(No difference)

Latest revision as of 09:05, 24 May 2017

To "profile" a language pair to see which part of the pipeline is the slowest, run each step one at a time. Here's a helper that will do that for you:

apertium_time_mode () {
    local mode=$1 print=$2
    local -a cmds res
    IFS=$'\0' res=( $(cat) )       # slurp into first element of array
    IFS=$'\n' cmds=( $(tr '|' '\n' < modes/"${mode}".mode | grep '[^ ]' | sed 's/[$]1/-d/g; s/[$]2//g' ) )
    for i in $(seq 0 "${#cmds[@]}"); do
        cmd="${cmds[$i]}"
        echo "$cmd"
        m=$(( i + 1 ))
        time res[$m]=$(echo "${res[$i]}" | eval "$cmd")
        if [[ -n $print ]]; then
            echo "${res[$m]}"
        fi
    done
}

Usage:

$ echo 'Boađus ii leat nu buorre go mun háliidan.'| apertium_time_mode sme-nob

to also see the output:

$ echo 'Boađus ii leat nu buorre go mun háliidan.'| apertium_time_mode sme-nob print