Skip to content

Commit 9c8145a

Browse files
committed
improvements to performance scripts
1 parent 09ab3f7 commit 9c8145a

File tree

2 files changed

+49
-29
lines changed

2 files changed

+49
-29
lines changed

scripts/perf/perf-diff.sh

Lines changed: 48 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,47 +20,67 @@ if [[ "$output_format" != "md" && "$output_format" != "csv" ]]; then
2020
exit 2
2121
fi
2222

23-
# Validate test name order and equality.
24-
# We trim leading/trailing whitespace on the first column before comparing.
25-
tmpdiff="$(mktemp)"
26-
if ! diff -u \
27-
--label "names before ($before_file)" --label "names after ($after_file)" \
28-
<(awk -F',' '{n=$1; sub(/^[ \t]+/,"",n); sub(/[ \t]+$/,"",n); print n}' "$before_file") \
29-
<(awk -F',' '{n=$1; sub(/^[ \t]+/,"",n); sub(/[ \t]+$/,"",n); print n}' "$after_file") \
30-
>"$tmpdiff"; then
31-
echo "ERROR: Test names differ between:"
32-
echo " before: $before_file"
33-
echo " and"
34-
echo " after: $after_file"
35-
echo " files."
36-
echo "Both files must have the same tests in the same order."
37-
echo
38-
cat "$tmpdiff"
39-
rm -f "$tmpdiff"
40-
exit 3
41-
fi
42-
rm -f "$tmpdiff"
43-
4423
if [ "$output_format" == "csv" ]; then
4524
echo "Test,Before,After,Percentage"
4625
else
4726
echo "| Test | Before | After | Percentage |"
4827
echo "| ---- | -----: | ----: | ---------: |"
4928
fi
5029

51-
paste -d, "$before_file" "$after_file" | while IFS=',' read -r test1 before test2 after; do
52-
if [ "$before" != "$after" ]; then
53-
diff=$((before - after))
54-
if [ "$before" -eq 0 ] 2>/dev/null; then
30+
BEFORE_FILE_CONTENTS="$(cat $before_file | sort | uniq)"
31+
AFTER_FILE_CONTENTS="$(cat $after_file | sort | uniq)"
32+
33+
TESTS_ONLY_BEFORE=""
34+
35+
shopt -s lastpipe # needed for the allow the above variable scope inside the loop
36+
echo "$BEFORE_FILE_CONTENTS" | while read BEFORE_LINE
37+
do
38+
TESTNAME="$(echo "$BEFORE_LINE" | cut -d"," -f1)"
39+
AFTER_LINE="$(echo "$AFTER_FILE_CONTENTS" | grep "$TESTNAME")"
40+
41+
BEFORE="$(echo "$BEFORE_LINE" | cut -d"," -f2)"
42+
43+
if [ -z "${AFTER_LINE}" ]; then
44+
# test only on before
45+
if [ "$output_format" == "csv" ]; then
46+
TESTS_ONLY_BEFORE="$TESTS_ONLY_BEFORE$TESTNAME,$BEFORE,,\\n"
47+
else
48+
TESTS_ONLY_BEFORE="$TESTS_ONLY_BEFORE| $TESTNAME | $BEFORE | | |\\n"
49+
fi
50+
else
51+
# test is on both files
52+
AFTER="$(echo "$AFTER_LINE" | cut -d"," -f2)"
53+
54+
diff=$(LC_NUMERIC=C awk -v after="$AFTER" -v before="$BEFORE" 'BEGIN { printf "%.2f", before - after }')
55+
if [ "$BEFORE" -eq 0 ] 2>/dev/null; then
5556
percent="NaN"
5657
else
57-
percent=$(LC_NUMERIC=C awk -v d="$diff" -v b="$before" 'BEGIN { printf "%.2f", (d / b) * 100 }')
58+
percent=$(LC_NUMERIC=C awk -v d="$diff" -v b="$BEFORE" 'BEGIN { printf "%.2f", (d / b) * 100 }')
5859
fi
60+
61+
if [ "$output_format" == "csv" ]; then
62+
echo "$TESTNAME,$BEFORE,$AFTER,$percent"
63+
else
64+
echo "| $TESTNAME | $BEFORE | $AFTER | ${percent}% |"
65+
fi
66+
fi
67+
done
68+
69+
echo -n -e "$TESTS_ONLY_BEFORE"
70+
71+
echo "$AFTER_FILE_CONTENTS" | while read AFTER_LINE
72+
do
73+
TESTNAME="$(echo "$AFTER_LINE" | cut -d"," -f1)"
74+
BEFORE_LINE="$(echo "$BEFORE_FILE_CONTENTS" | grep "$TESTNAME")"
75+
76+
AFTER="$(echo "$AFTER_LINE" | cut -d"," -f2)"
5977

78+
if [ -z "${BEFORE_LINE}" ]; then
79+
# test only on after
6080
if [ "$output_format" == "csv" ]; then
61-
echo "$test1,$before,$after,$percent"
81+
echo "$TESTNAME,,$AFTER,"
6282
else
63-
echo "| $test1 | $before | $after | ${percent}% |"
83+
echo "| $TESTNAME | | $AFTER | |"
6484
fi
6585
fi
6686
done

test/src/e2e_vm_tests/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ impl TestContext {
829829
}
830830
for test in pkg.tests.into_iter() {
831831
perf_data.gas_usages.push(GasUsage::with_unit_test_name(
832-
test.name.clone(),
832+
format!("{}::{}", pkg.built.descriptor.name, test.name),
833833
test.gas_used as usize,
834834
));
835835
if verbose {

0 commit comments

Comments
 (0)