summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorVitaly Minko <vitaly.minko@gmail.com>2018-01-31 19:29:32 +0300
committerVitaly Minko <vitaly.minko@gmail.com>2018-01-31 19:29:32 +0300
commit2915eb07b2159d75b1ead13fdde0d73adff728fa (patch)
tree3a1a80a4d7660337ac94b69cdf6d138f7d011499 /utils
parent32991b5093444b8392035a8ac5b62dba74372e0e (diff)
Implemented tests and utilities for benchmarking proof-of-work.
Diffstat (limited to 'utils')
-rwxr-xr-xutils/benchmark_pow.sh49
-rw-r--r--utils/pow_histogram.gp22
2 files changed, 71 insertions, 0 deletions
diff --git a/utils/benchmark_pow.sh b/utils/benchmark_pow.sh
new file mode 100755
index 0000000..98fa720
--- /dev/null
+++ b/utils/benchmark_pow.sh
@@ -0,0 +1,49 @@
+#!/bin/sh
+#
+# This file is used for running Proof-of-Work benchmarks, generating
+# histograms and calculating average time to find the proof.
+#
+# (c) 2018 Vitaly Minko <vitaly.minko@gmail.com>
+
+COUNT=10
+BIT_NUM=16
+TEST_TYPE=BenchmarkPoW
+DATAFILE=histogram.dat
+IMGFILE=pow_histogram.png
+DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+
+if [ $# -gt 2 ] || [ "$1" == "-h" ]
+then
+ cat >&2 << EOF
+Usage:
+ $0 [bit_num] [count]
+where,
+ [bit_num] is either 8 or 16. Default value is ${BIT_NUM}.
+ [count] specifies how many times to run [test_name]. Default value is ${COUNT}.
+EOF
+ exit 1
+fi
+
+if [ -n "$1" ]; then
+ BIT_NUM=$1
+fi
+TEST_NAME="${TEST_TYPE}${BIT_NUM}"
+
+if [ -n "$2" ]; then
+ COUNT=$2
+fi
+
+echo "Starting benchmark. Use 'tail -f benchmark.log' to monitor the progress."
+go test -bench=$TEST_NAME -benchtime=1ns -timeout=24h -count=$COUNT > benchmark.log
+echo "The benchmark is over."
+cat benchmark.log | grep $TEST_NAME | awk '{print $3/1E9}' > $DATAFILE
+
+echo -n "The average time to find proof is: "
+awk '{ total += $1; count++ } END { print total/count }' $DATAFILE
+
+gnuplot -e "infile='$DATAFILE'" \
+ -e "bitnum=$BIT_NUM" \
+ -e "count=$COUNT" \
+ -e "outfile='$IMGFILE'" \
+ $DIR/pow_histogram.gp
+echo "The histogram is ready: ${IMGFILE}."
diff --git a/utils/pow_histogram.gp b/utils/pow_histogram.gp
new file mode 100644
index 0000000..ad072f1
--- /dev/null
+++ b/utils/pow_histogram.gp
@@ -0,0 +1,22 @@
+# This script has three parameters:
+# infile - input file with the data
+# outfile - output file (image)
+# bitnum - number of zero bits in PoW
+# count - number of samples in the input data
+
+set xlabel 'T, sec'
+set ylabel 'Frequency'
+
+width=0.2
+set boxwidth width*1
+bin(x,width)=width*floor(x/width)+width/2.0
+
+set style fill solid 0.4
+
+set term png
+set output outfile
+
+plot infile using (bin($1,width)):(1.0) \
+ smooth freq with boxes \
+ title "\nTime to find ".bitnum."-bit PoW\n(".count." samples, binsize = 0.2 sec)" \
+ linecolor rgb "#55AA55"