OILS / benchmarks / parse-help.sh View on Github | oilshell.org

65 lines, 32 significant
1#!/usr/bin/env bash
2#
3# A pure string-processing benchmark extracted from bash-completion.
4#
5# Note: most stuff moved to benchmarks/compute.
6#
7# Usage:
8# benchmarks/parse-help.sh <function name>
9
10set -o nounset
11set -o pipefail
12set -o errexit
13
14REPO_ROOT=$(cd "$(dirname $0)/.."; pwd)
15source build/common.sh
16
17readonly DATA_DIR='benchmarks/parse-help'
18readonly EXCERPT=benchmarks/parse-help/excerpt.sh
19
20collect() {
21 mkdir -p $DATA_DIR
22
23 ls --help > $DATA_DIR/ls.txt
24 ~/.local/bin/mypy --help > $DATA_DIR/mypy.txt
25
26 wc -l $DATA_DIR/*
27}
28
29collect-clang() {
30 $CLANGXX --help > $DATA_DIR/clang.txt
31}
32
33shorten() {
34 egrep '^[ ]+-' $DATA_DIR/ls.txt | head -n 2 | tee $DATA_DIR/ls-short.txt
35}
36
37TIMEFORMAT='%U'
38
39# Geez:
40# ls mypy
41# bash 25ms 25ms
42# OSH 600ms 900ms There is a lot of variance here too.
43
44# Well I guess that is 25x slower? It's a computationally expensive thing.
45# Oh part of this is because printf is not a builtin! Doh.
46#
47# TODO
48# - count the number of printf invocations. But you have to do it recursively!
49# - Turn this into a proper benchmark with an HTML page.
50
51one() {
52 local sh='bin/osh'
53 local cmd='ls-short'
54 export PS4='+[${LINENO}:${FUNCNAME[0]}] '
55 time cat $DATA_DIR/$cmd.txt | $sh -x $EXCERPT _parse_help -
56}
57
58compare-one() {
59 local cmd='ls-short'
60 time cat $DATA_DIR/$cmd.txt | bin/osh $EXCERPT _parse_help -
61 echo ---
62 time cat $DATA_DIR/$cmd.txt | bash $EXCERPT _parse_help -
63}
64
65"$@"