OILS / benchmarks / startup.sh View on Github | oilshell.org

165 lines, 92 significant
1#!/usr/bin/env bash
2#
3# Usage:
4# ./startup.sh <function name>
5
6set -o nounset
7set -o pipefail
8set -o errexit
9
10readonly TIMEFORMAT='%R'
11
12# 3 groups:
13# dash/mksh/lua/awk: < 90 syscalls
14# bash/zsh/perl: 145-289 syscalls
15# python -S/python3 -S/ruby: 200-800 syscalls
16
17# This throws off absolute timing, but relative still makes sense.
18# TODO: get rid of wc -l if not.
19
20# Ubuntu inside Virtualbox on Macbook Air:
21#
22# dash/mksh/mawk: 1 ms
23# bash/gawk/perl: 2 ms
24# zsh: 3 ms
25# python -S: 5 ms
26# python3 -S : 13 ms
27# python import: 16 ms
28# app.zip / hello.ovm: 10 ms
29# oil true: 46 ms
30# oil echo hi: 59 ms
31
32strace-callback() {
33 strace "$@" 2>&1 | wc -l
34}
35
36time-callback() {
37 time "$@" >/dev/null
38}
39
40compare() {
41 local callback=${1:-strace-callback}
42
43 # dash is the fastest: 0 ms.
44 for sh in bash dash mksh zsh; do
45 echo $sh
46 $callback $sh -c 'echo "hi" > /dev/null'
47 echo
48 done
49
50 # gawk is slower than mawk
51 for awk in gawk mawk; do
52 echo $awk
53 $callback $awk '{ print "hi" } ' < /dev/null
54 echo
55 done
56
57 if which lua; then
58 echo lua
59 $callback lua -e 'print "hi"'
60 echo
61 fi
62
63 echo perl
64 $callback perl -e 'print "hi\n"'
65 echo
66
67 # Woah 247 ms? Ruby is slower than Python.
68 if which ruby; then
69 echo ruby
70 $callback ruby -e 'print "hi\n"'
71 echo
72 fi
73
74 # Oh almost all stats come from -S!
75 for py in python python3; do
76 echo $py -S
77 $callback $py -S -c 'print("hi")'
78 echo
79 done
80
81 for py in python python3; do
82 echo $py import
83 $callback $py -S -c 'import json;print("hi")'
84 echo
85 done
86
87 for py in python python3; do
88 echo $py import
89 $callback $py -S -c 'import json;print("hi")'
90 echo
91 done
92
93 echo 'Small app.zip'
94 $callback python -S _tmp/app.zip
95 echo
96
97 # This is close to app.zip, a few milliseconds slower.
98 echo 'hello app bundle'
99 $callback _bin/hello.ovm || true
100 echo
101
102 echo 'OSH app bundle true'
103 $callback _bin/true
104 echo
105
106 echo 'OSH app bundle Hello World'
107 $callback _bin/osh -c 'echo hi'
108 echo
109}
110
111compare-strace() {
112 compare strace-callback
113}
114
115compare-time() {
116 compare time-callback
117}
118
119import-stats() {
120 # 152 sys calls! More than bash needs to start up.
121 echo json
122 strace python -c 'import json' 2>&1 | grep json | wc -l
123
124 echo nonexistent___
125 strace python -c 'import nonexistent___' 2>&1 | grep nonexistent___ | wc -l
126}
127
128make-zip() {
129 rm -r -f _tmp/app
130 rm -f _tmp/app.zip
131
132 mkdir -p _tmp/app
133
134 cat > _tmp/app/lib1.py <<EOF
135print "hi from lib1"
136EOF
137
138 cat > _tmp/app/lib2.py <<EOF
139print "hi from lib2"
140EOF
141
142 cat > _tmp/app/__main__.py <<EOF
143import sys
144sys.path = [sys.argv[0]]
145import lib1
146import lib2
147print "hi from zip"
148EOF
149
150 pushd _tmp/app
151 zip -r ../app.zip .
152 popd
153}
154
155# Can get this down to 5 ms, 593 syscalls. Needs to be much less.
156test-zip() {
157 python -S _tmp/app.zip
158}
159
160# This still tries to import encodings and stuff like that.
161strace-zip() {
162 strace python -S _tmp/app.zip
163}
164
165"$@"