Ticket #26: shell-perf.sh

File shell-perf.sh, 560 bytes (added by dmik, 9 years ago)
Line 
1#
2# Simple performance test for POSIX-compliant shells
3#
4# Usage: time env -i <shell> shell-perf.sh [<num subshells>]
5#
6# Written by Mathias Lafeldt <mathias.lafeldt@gmail.com>
7
8# for linux OS
9#shell="$(ps -o pid,command | awk "\$1 == $$ { print \$2 }")"
10
11# for OS/2
12xpid=$(printf %X $$)
13shell="$(pstat /p:$xpid | grep ^$xpid | awk "{ print \$4 }")"
14
15forks=${1:-1000}
16 
17echo -n "Forking $forks $shell subshells"
18 
19for i in $(seq 1 $forks); do
20    "$shell" -c 'echo -n .; j=1; while [ $j -le 1000 ]; do j=$(($j+1)); done'
21done
22 
23echo ""