From 3a7bdcc020d0c68703c53ea37e86cd8bc9640904 Mon Sep 17 00:00:00 2001 From: Stanislav Bogatyrev Date: Fri, 10 Feb 2023 15:57:35 +0300 Subject: [PATCH] [#3] Simplify demo and benchmark No need to build everything every time and no need to do it in docker. Signed-off-by: Stanislav Bogatyrev --- auto.sh | 35 ----------------------------------- benchmark => benchmark.sh | 4 +--- demo.sh | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 38 deletions(-) delete mode 100755 auto.sh rename benchmark => benchmark.sh (76%) create mode 100755 demo.sh diff --git a/auto.sh b/auto.sh deleted file mode 100755 index f4bf9ac..0000000 --- a/auto.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env bash - -B="\033[0;1m" -G="\033[0;92m" -R="\033[0m" - -echo -e "${B}${G}Let's make some hash${R}" - -echo -e "\n${B}${G} - cleanup environment${R}" -echo -e "remove files: small.hash, large.hash, large.txt" -docker exec -it hash-demo sh -c "rm -rf small.hash" -docker exec -it hash-demo sh -c "rm -rf large.hash" -docker exec -it hash-demo sh -c "rm -rf large.txt" - -echo -e "\n${B}${G} - make large file (concat small files)${R}" -for i in $(seq -f "%02g" 10) -do - echo " #> cat $i.txt >> large.txt" - docker exec -it hash-demo sh -c "cat $i.txt >> large.txt" -done - -echo -e "\n${B}${G} - make hash of small files${R}" -for i in $(seq -f "%02g" 10) -do - echo -e " #> homo -file $i.txt | tee -a small.hash" - docker exec -it hash-demo sh -c "homo -file $i.txt | tee -a small.hash" -done - -echo -e "\n${B}${G} - make hash of large${R}" -echo -e " #> homo -file large.txt | homo -concat" -docker exec -it hash-demo sh -c 'homo -file large.txt | homo -concat' - -echo -e "\n${B}${G} - make hash of pieces${R}" -echo -e " #> cat small.hash | homo -concat" -docker exec -it hash-demo sh -c 'cat small.hash | homo -concat ' \ No newline at end of file diff --git a/benchmark b/benchmark.sh similarity index 76% rename from benchmark rename to benchmark.sh index 6c9347d..3d16e40 100755 --- a/benchmark +++ b/benchmark.sh @@ -5,10 +5,8 @@ OUT="${OUT:-$(mktemp /tmp/random-file.XXXXXX)}" dd if=/dev/urandom of="$OUT" bs="$BLOCK_SIZE" count=1 -go build ./cmd/tzsum || exit 1 - for impl in avx avx2 generic; do echo $impl implementation: - time ./tzsum -name "$OUT" -impl $impl + time ./bin/tzsum -name "$OUT" -impl $impl echo done diff --git a/demo.sh b/demo.sh new file mode 100755 index 0000000..5537785 --- /dev/null +++ b/demo.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +#set -x + +BLOCK_SIZE=${1:-100M} # 100Mb by default +TMPDIR="${TMPDIR:-$(mktemp -d)}" + +OUT="${OUT:-"${TMPDIR}/bighash"}" + +echo "Preparing big file at ${OUT}..." +dd if=/dev/urandom of="$OUT" bs="$BLOCK_SIZE" count=1 + +echo "Make 4 smaller parts from ${OUT}..." +split -dn 4 "${OUT}" "${TMPDIR}/" + +echo -n "Big file hash: " +TZALL=$(./bin/tzsum -impl avx2 -name "${OUT}" | awk '{print $1}') +echo "${TZALL}" + +for i in $(seq -f "%02g" 0 3) +do + echo -n "Part ${i} hash: " + PART=$(./bin/tzsum -impl avx2 -name "${TMPDIR}/${i}" | awk '{print $1}') + echo "${PART}" | tee -a "${TMPDIR}/part.hashes" +done + +echo -n "Cumulative: " +TZCUM=$(./bin/homo -concat -file "${TMPDIR}/part.hashes") +echo "${TZCUM}" + +if [[ "$TZCUM" == "$TZALL" ]]; then + echo "Original and cumulative hashes are equal!" +else + echo "Original and cumulative hashes are NOT equal!" +fi + +echo -ne "Cleaning up .. " +rm -rf "${TMPDIR}" +echo "Done!"