-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
benchmark.sh
executable file
·95 lines (72 loc) · 3.48 KB
/
benchmark.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
#!/bin/sh
_SUBSTRUCTION () {
echo | awk "{printf \"%.3f\", $1-$2}"
}
_MESSAGE_FORMATTER () {
awk '{printf "| %-28s | %9s |\n",$1" "$2,$3}'
}
LOG_TABLE () {
time_begin=$(date +%s -d "$(awk '/.*DEBUG Hexo version/{print $1}' build.log)")
time_process_start=$(date +%s.%3N -d "$(awk '/.*INFO Start processing/{print $1}' build.log)")
time_render_start=$(date +%s.%3N -d "$(awk '/.*INFO Files loaded in/{print $1}' build.log)")
time_render_finish=$(date +%s.%3N -d "$(awk '/.*INFO.*generated in /{print $1}' build.log)")
time_database_saved=$(date +%s.%3N -d "$(awk '/.*DEBUG Database saved/{print $1}' build.log)")
memory_usage=$(awk '/.*Maximum resident set size/{print $6}' build.log)
echo "Load Plugin/Scripts/Database $(_SUBSTRUCTION $time_process_start $time_begin)s" | _MESSAGE_FORMATTER
echo "Process Source $(_SUBSTRUCTION $time_render_start $time_process_start)s" | _MESSAGE_FORMATTER
echo "Render Files $(_SUBSTRUCTION $time_render_finish $time_render_start)s" | _MESSAGE_FORMATTER
echo "Save Database $(_SUBSTRUCTION $time_database_saved $time_render_finish)s" | _MESSAGE_FORMATTER
echo "Total time $(_SUBSTRUCTION $time_database_saved $time_begin)s" | _MESSAGE_FORMATTER
echo "Memory Usage(RSS) $(echo | awk "{printf \"%.3f\", $memory_usage/1024}")MB" | _MESSAGE_FORMATTER
total_time=$(_SUBSTRUCTION $time_database_saved $time_begin | xargs -0 printf "%.0f")
line_number=$(wc -l build.log | cut -d" " -f1)
if [ "$1" != "HOT" ]; then
if [ "$total_time" -lt 10 ] || [ "$line_number" -lt 300 ]; then
echo "--------------------------------------------"
echo -e '\033[41;37m !! Build failed !! \033[0m'
head -n 400 build.log
exit 1
fi
fi
if [ "$total_time" -gt 40 ]; then
echo "--------------------------------------------"
echo -e '\033[41;37m !! Performance regression detected !! \033[0m'
exit 1
fi
}
echo "============== Hexo Benchmark =============="
echo "- Set up dummy Hexo site"
cd $TRAVIS_BUILD_DIR
cd ..
git clone https://github.com/hexojs/hexo-theme-unit-test.git --depth=1 --quiet
cd hexo-theme-unit-test
echo "- Install hexo-theme-landscape"
git clone https://github.com/hexojs/hexo-theme-landscape --depth=1 --quiet themes/landscape
echo "- npm install"
npm install --silent
echo "- Import 300 posts"
git clone https://github.com/SukkaLab/hexo-many-posts.git source/_posts/hexo-many-posts --depth=1 --quiet
rm -rf source/_posts/hexo-many-posts/.git/
echo "- Replace node_modules/hexo"
rm -rf node_modules/hexo
ln -sf $TRAVIS_BUILD_DIR node_modules/hexo
echo "- Start test run"
echo ""
echo "------------- Cold processing --------------"
{ /usr/bin/time -v npx --no-install hexo g --debug > build.log 2>&1 ; } 2> build.log
LOG_TABLE
echo "-------------- Hot processing --------------"
{ /usr/bin/time -v npx --no-install hexo g --debug > build.log 2>&1 ; } 2> build.log
LOG_TABLE "HOT"
echo "--------- Another Cold processing ----------"
npx --no-install hexo clean > build.log
{ /usr/bin/time -v npx --no-install hexo g --debug > build.log 2>&1 ; } 2> build.log
LOG_TABLE
echo "--------------------------------------------"
npx --no-install hexo clean > build.log
echo ""
echo "- Generating flamegraph..."
0x --output-dir "${TRAVIS_BUILD_DIR}/0x" -- node ./node_modules/.bin/hexo g > build.log 2>&1 ;
echo "Flamegraph will be deployed to: https://${TRAVIS_COMMIT}-${TRAVIS_NODE_VERSION}-hexo.surge.sh/flamegraph.html"
rm -rf build.log
cd $TRAVIS_BUILD_DIR