forked from trufflesecurity/trufflehog
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add scripts to benchmark and plot performance across tags (trufflesec…
…urity#1293) * add scripts to benchmark and plot performance across tags * missing newline * fmt
- Loading branch information
1 parent
10902f8
commit 4086895
Showing
5 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
set terminal png size 800,600 | ||
set output "hack/bench/versions.png" | ||
|
||
set title "User Time vs. Version" | ||
set xlabel "Version" | ||
set ylabel "Average User Time (s)" | ||
|
||
set xtics rotate by -45 | ||
|
||
plot "hack/bench/plot.txt" using 2:xtic(1) with linespoints linestyle 1 notitle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/bash | ||
|
||
if [ $# -ne 2 ]; then | ||
echo "Usage: $0 <repository to clone> <number_of_versions_back_to_test>" | ||
exit 1 | ||
fi | ||
|
||
# Get the number of versions back to test from command line argument | ||
num_versions="$2" | ||
|
||
test_repo="$1" | ||
|
||
bash hack/bench/versions.sh $test_repo $num_versions | tee hack/bench/plot.txt | ||
|
||
gnuplot hack/bench/plot.gp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
v3.33.0: 1.402 | ||
v3.32.2: 1.298 | ||
v3.32.1: 1.332 | ||
v3.32.0: 1.348 | ||
v3.31.6: 2.470 | ||
v3.31.5: 2.462 | ||
v3.31.4: 2.460 | ||
v3.31.3: 2.418 | ||
v3.31.2: 1.384 | ||
v3.31.1: 1.344 | ||
v3.31.0: 1.354 | ||
v3.30.0: 1.392 | ||
v3.29.1: 1.382 | ||
v3.29.0: 1.340 | ||
v3.28.7: 1.380 | ||
v3.28.6: 1.308 | ||
v3.28.5: 2.596 | ||
v3.28.4: 2.554 | ||
v3.28.3: 2.582 | ||
v3.28.1: 2.578 | ||
v3.28.2: 2.566 | ||
v3.28.0: 2.552 | ||
v3.27.1: 2.574 | ||
v3.26.0: 2.538 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#!/bin/bash | ||
|
||
if [ $# -ne 2 ]; then | ||
echo "Usage: $0 <repository to clone> <number_of_versions_back_to_test>" | ||
exit 1 | ||
fi | ||
|
||
# Get the number of versions back to test from command line argument | ||
num_versions="$2" | ||
|
||
test_repo="$1" | ||
|
||
num_iterations=5 | ||
|
||
# Create a temporary folder to clone the repository | ||
repo_tmp=$(mktemp -d) | ||
# Set up a trap to remove the temporary folder on exit or failure | ||
trap "rm -rf $repo_tmp" EXIT | ||
# Clone the test repository to a temporary folder | ||
git clone --quiet "$test_repo" $repo_tmp | ||
|
||
|
||
# Get list of git tags, sorted from newest to oldest | ||
tags=$(git tag --sort=-creatordate) | ||
|
||
# Counter to keep track of number of tags checked out | ||
count=0 | ||
|
||
|
||
# Loop over tags and checkout each one in turn, up to the specified number of versions | ||
for tag in $tags | ||
do | ||
if [[ $count -eq $num_versions ]]; then | ||
break | ||
fi | ||
|
||
# Skip RC tags | ||
if [[ $tag == *"rc"* ]]; then | ||
continue | ||
fi | ||
|
||
# Skip alpha tags | ||
if [[ $tag == *"alpha"* ]]; then | ||
continue | ||
fi | ||
|
||
# Use git checkout with the quiet flag to suppress output | ||
git checkout $tag --quiet | ||
|
||
# Run make install with suppressed output | ||
make install > /dev/null | ||
|
||
# Initialize the variable to store the sum of user times | ||
user_time_sum=0 | ||
|
||
# Run each iteration 5 times and calculate the average user time | ||
for i in {1..$num_iterations} | ||
do | ||
# Run trufflehog with suppressed output and capture user time with /usr/bin/time | ||
tmpfile=$(mktemp) | ||
/usr/bin/time -o $tmpfile trufflehog git "file://$repo_tmp" --no-verification --no-update >/dev/null 2>&1 | ||
time_output=$(cat $tmpfile) | ||
rm $tmpfile | ||
|
||
# Extract the user time from the output | ||
user_time=$(echo $time_output | awk '{print $3}') | ||
|
||
# Add the user time to the sum | ||
user_time_sum=$(echo "$user_time_sum + $user_time" | bc) | ||
done | ||
|
||
# Calculate the average user time | ||
average_user_time=$(echo "scale=3; $user_time_sum / $num_iterations" | bc) | ||
|
||
# Print the average user time output for this iteration in the specified format | ||
echo "$tag: $average_user_time" | ||
|
||
# Increment the counter | ||
count=$((count+1)) | ||
done |