This repository has been archived by the owner on Feb 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
memory-bench.sh
executable file
·99 lines (87 loc) · 2.38 KB
/
memory-bench.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env bash
BROWSER=$1
TESTSET=$2
DURATION=20
REPEATS=3
case $BROWSER in
Brave )
PROCESS_NAMES="Brave Browser"
EXECUTABLE="/Applications/Brave Browser Nightly.app"
APPLICATION="Brave Browser"
;;
Firefox )
PROCESS_NAMES="firefox|plugin-container"
EXECUTABLE="/Applications/Firefox.app"
APPLICATION="Firefox"
;;
Safari )
PROCESS_NAMES="Safari|WebKit"
EXECUTABLE="/Applications/Safari.app"
APPLICATION="Safari"
;;
Chrome )
PROCESS_NAMES="Google Chrome"
EXECUTABLE="/Applications/Google Chrome.app"
APPLICATION="Google Chrome"
;;
ChromeUBO )
PROCESS_NAMES="Google Chrome"
EXECUTABLE="/Applications/Google Chrome.app"
FLAGS="--load-extension=$(pwd)/uBO"
APPLICATION="Google Chrome"
;;
Opera )
PROCESS_NAMES="Opera"
EXECUTABLE="/Users/brave/Applications/Opera Beta.app"
APPLICATION="Opera Beta"
;;
Edge )
PROCESS_NAMES="Microsoft Edge"
EXECUTABLE="/Applications/Microsoft Edge Beta.app"
APPLICATION="Microsoft Edge"
;;
esac
for TEST in ./scenarios/$TESTSET*.txt
do
echo "$BROWSER Processing $TEST file..."
IFS=$'\n' read -d '' -r -a PAGES < ${TEST}
for (( i = 0; i < $REPEATS; i++ )); do
open -a "$EXECUTABLE" --args ${FLAGS} #> /dev/null 2>&1 &
sleep 3 # Wait a little bit for the app to start
# IFS=' ' read -r -a openpages <<< "$TEST"
for url in "${PAGES[@]}"
do
command="tell application \"$APPLICATION\" to open location \"$url\""
osascript -e "$command"
sleep 5; # Sleep for 5 seconds after each page opened
done
# read -r -d '' cycle_tabs << EOM
# tell application "${APPLICATION}"
# set i to 0
# repeat with t in (tabs of (first window whose index is 1))
# set i to i + 1
# set (active tab index of (first window whose index is 1)) to i
# delay 2
# end repeat
# end tell
# EOM
# osascript -e "$cycle_tabs"
sleep $DURATION
echo "Calculating memory use"
top -l 1 -stats mem,command \
| egrep "$PROCESS_NAMES" \
| awk -v run=$i -v browser=$BROWSER '{
ex = index("KMGTPEZY", substr($1, length($1), 1));
val = substr($1, 0, length($1) - 1)
prod = val * 1024^ex
sum += prod
}
END {print browser " run " run ": total memory " sum / 1024 / 1024 " MB"}';
echo "Terminating"
closewindow="tell application \"${APPLICATION}\" to close window 1"
quit="quit app \"${APPLICATION}\""
osascript -e "$closewindow"
osascript -e "$quit"
sleep 3
done
done