Debian Codegraph @

vendor/wikimedia/wikipeg/tools/impact

raw symbols SCIP
1 #!/bin/shscip-shell filesystem . . `/bin/sh`.
2
3 # Measures impact of a Git commit (or multiple commits) on generated parsers'
4 # speed and size. Makes sense to use only on PEG.js Git repository checkout.
5
6 set -e
7
8 # Measurement
9
10 preparescip-shell shell shell-project 0.0.0 prepare().() {
11 gitscip-shell system . . git. checkout --quiet "$1"
12 }
13
14 run_benchmarkscip-shell shell shell-project 0.0.0 run_benchmark().() {
15 echoscip-shell system . . echo. $(makescip-shell system . . make. benchmark | awkscip-shell system . . awk. 'BEGIN { FS = " *│ *" } /Total/ { split($5, a, " "); print a[1] }')
16 }
17
18 measure_speedscip-shell shell shell-project 0.0.0 measure_speed().() {
19 bc <<-EOT
20 scale = 2
21 ($(run_benchmarkscip-shell shell shell-project 0.0.0 run_benchmark().) + $(run_benchmarkscip-shell shell shell-project 0.0.0 run_benchmark().) + $(run_benchmarkscip-shell shell shell-project 0.0.0 run_benchmark().) + $(run_benchmarkscip-shell shell shell-project 0.0.0 run_benchmark().) + $(run_benchmarkscip-shell shell shell-project 0.0.0 run_benchmark().)) / 5
22 EOT
23 }
24
25 measure_sizescip-shell shell shell-project 0.0.0 measure_size().() {
26 for file in examples/*.pegjs; do
27 bin/wikipeg "$file"
28 done
29
30 echoscip-shell system . . echo. $(catscip-shell system . . cat. examples/*.js | wcscip-shell system . . wc. -c)
31
32 rmscip-shell system . . rm. examples/*.js
33 }
34
35 differencescip-shell shell shell-project 0.0.0 difference().() {
36 bc <<-EOT
37 scale = 4
38 ($2 / $1 - 1) * 100
39 EOT
40 }
41
42 # Helpers
43
44 print_resultsscip-shell shell shell-project 0.0.0 print_results().() {
45 echoscip-shell system . . echo.
46
47 echoscip-shell system . . echo. "Speed impact"
48 echoscip-shell system . . echo. "------------"
49 echoscip-shell system . . echo. "Before: $1 kB/s"
50 echoscip-shell system . . echo. "After: $2 kB/s"
51 printfscip-shell system . . printf. "Difference: %0.2f%%\n" $(differencescip-shell shell shell-project 0.0.0 difference(). $1 $2)
52
53 echoscip-shell system . . echo.
54
55 echoscip-shell system . . echo. "Size impact"
56 echoscip-shell system . . echo. "-----------"
57 echoscip-shell system . . echo. "Before: $3 b"
58 echoscip-shell system . . echo. "After: $4 b"
59 printfscip-shell system . . printf. "Difference: %0.2f%%\n" $(differencescip-shell shell shell-project 0.0.0 difference(). $3 $4)
60
61 echoscip-shell system . . echo.
62
63 echoscip-shell system . . echo. "(Measured by /tools/impact with Node.js $(nodescip-shell system . . node. --version) on $(unamescip-shell system . . uname. --operating-system --machine).)"
64 }
65
66 print_usagescip-shell shell shell-project 0.0.0 print_usage().() {
67 echoscip-shell system . . echo. "Usage:"
68 echoscip-shell system . . echo. " $0 <commit>"
69 echoscip-shell system . . echo. " $0 <commit_before> <commit_after>"
70 echoscip-shell system . . echo.
71 echoscip-shell system . . echo. "Measures impact of a Git commit (or multiple commits) on generated parsers'"
72 echoscip-shell system . . echo. "speed and size. Makes sense to use only on PEG.js Git repository checkout."
73 }
74
75 cd_to_rootscip-shell shell shell-project 0.0.0 cd_to_root().() {
76 if [scip-shell system . . `[`. -L "$0" ]; then
77 THIS_FILE=$(readlinkscip-shell system . . readlink. "$0")
78 else
79 THIS_FILE="$0"
80 fi
81 cd "$(dirnamescip-shell system . . dirname. "$THIS_FILE")/.."
82 }
83
84 exit_failurescip-shell shell shell-project 0.0.0 exit_failure().() {
85 exit 1
86 }
87
88 # Main
89
90 if [scip-shell system . . `[`. $# -eq 1 ]; then
91 commit_before="$1~1"
92 commit_after="$1"
93 elif [scip-shell system . . `[`. $# -eq 2 ]; then
94 commit_before="$1"
95 commit_after="$2"
96 else
97 print_usagescip-shell shell shell-project 0.0.0 print_usage().
98 exit_failurescip-shell shell shell-project 0.0.0 exit_failure().
99 fi
100
101 cd_to_rootscip-shell shell shell-project 0.0.0 cd_to_root().
102
103 echoscip-shell system . . echo. -n "Measuring commit $commit_before..."
104 preparescip-shell shell shell-project 0.0.0 prepare(). "$commit_before"
105 speed1=$(measure_speedscip-shell shell shell-project 0.0.0 measure_speed().)
106 size1=$(measure_sizescip-shell shell shell-project 0.0.0 measure_size().)
107 echoscip-shell system . . echo. " OK"
108
109 echoscip-shell system . . echo. -n "Measuring commit $commit_after..."
110 preparescip-shell shell shell-project 0.0.0 prepare(). "$commit_after"
111 speed2=$(measure_speedscip-shell shell shell-project 0.0.0 measure_speed().)
112 size2=$(measure_sizescip-shell shell shell-project 0.0.0 measure_size().)
113 echoscip-shell system . . echo. " OK"
114
115 print_resultsscip-shell shell shell-project 0.0.0 print_results(). $speed1 $speed2 $size1 $size2