Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/BLAKE2/BLAKE2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/bench
diff options
context:
space:
mode:
authorCodesInChaos <CodesInChaos@gmail.com>2013-02-01 19:44:36 +0400
committerCodesInChaos <CodesInChaos@gmail.com>2013-02-01 19:44:36 +0400
commitfb714d2c830ec524bd3cbb5a45fe70fd90fe5c84 (patch)
tree477d30f1a1b38fef59a24470ae200ab6065285f0 /bench
Release 2013-01-31
Diffstat (limited to 'bench')
-rw-r--r--bench/amd64cpuinfo.c20
-rw-r--r--bench/bench.c68
-rw-r--r--bench/do.gplot16
-rw-r--r--bench/makefile16
-rw-r--r--bench/md5.c21
-rw-r--r--bench/x86cpuinfo.c19
6 files changed, 160 insertions, 0 deletions
diff --git a/bench/amd64cpuinfo.c b/bench/amd64cpuinfo.c
new file mode 100644
index 0000000..479ec4b
--- /dev/null
+++ b/bench/amd64cpuinfo.c
@@ -0,0 +1,20 @@
+/*
+ BLAKE2 reference source code package - benchmark tool
+
+ Written in 2012 by Samuel Neves <sneves@dei.uc.pt>
+
+ To the extent possible under law, the author(s) have dedicated all copyright
+ and related and neighboring rights to this software to the public domain
+ worldwide. This software is distributed without any warranty.
+
+ You should have received a copy of the CC0 Public Domain Dedication along with
+ this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
+*/
+
+unsigned long long cpucycles( void )
+{
+ unsigned long long result;
+ asm volatile( ".byte 15;.byte 49;shlq $32,%%rdx;orq %%rdx,%%rax"
+ : "=a" ( result ) :: "%rdx" );
+ return result;
+}
diff --git a/bench/bench.c b/bench/bench.c
new file mode 100644
index 0000000..3e86fa1
--- /dev/null
+++ b/bench/bench.c
@@ -0,0 +1,68 @@
+/*
+ BLAKE2 reference source code package - benchmark tool
+
+ Written in 2012 by Samuel Neves <sneves@dei.uc.pt>
+
+ To the extent possible under law, the author(s) have dedicated all copyright
+ and related and neighboring rights to this software to the public domain
+ worldwide. This software is distributed without any warranty.
+
+ You should have received a copy of the CC0 Public Domain Dedication along with
+ this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
+*/
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+int crypto_hash( unsigned char *out, const unsigned char *in, unsigned long long inlen );
+
+static int bench_cmp( const void *x, const void *y )
+{
+ const int64_t *ix = ( const int64_t * )x;
+ const int64_t *iy = ( const int64_t * )y;
+ return *ix - *iy;
+}
+
+unsigned long long cpucycles( void );
+
+void bench()
+{
+#define BENCH_TRIALS 32
+#define BENCH_MAXLEN 1536
+ static unsigned char in[4096];
+ static unsigned long long median[4096 + 1];
+ int i, j;
+ printf( "#bytes median per byte\n" );
+
+ /* 1 ... BENCH_MAXLEN */
+ for( j = 0; j <= 4096; ++j )
+ {
+ uint64_t cycles[BENCH_TRIALS + 1];
+
+ for( i = 0; i <= BENCH_TRIALS; ++i )
+ {
+ cycles[i] = cpucycles();
+ crypto_hash( in, in, j );
+ }
+
+ for( i = 0; i < BENCH_TRIALS; ++i )
+ cycles[i] = cycles[i + 1] - cycles[i];
+
+ qsort( cycles, BENCH_TRIALS, sizeof( uint64_t ), bench_cmp );
+ median[j] = cycles[BENCH_TRIALS / 2];
+ }
+
+ for( j = 0; j <= BENCH_MAXLEN; j += 8 )
+ printf( "%5d, %7.2f\n", j, ( double )median[j] / j );
+
+ printf( "#2048 %6llu %7.2f\n", median[2048], ( double )median[2048] / 2048.0 );
+ printf( "#4096 %6llu %7.2f\n", median[4096], ( double )median[4096] / 4096.0 );
+ printf( "#long long %7.2f\n", ( double )( median[4096] - median[2048] ) / 2048.0 );
+}
+
+int main()
+{
+ bench();
+ return 0;
+}
diff --git a/bench/do.gplot b/bench/do.gplot
new file mode 100644
index 0000000..a9a8f6a
--- /dev/null
+++ b/bench/do.gplot
@@ -0,0 +1,16 @@
+maxx = 256
+set xrange [1:maxx]
+set xlabel "bytes "
+set ylabel "cycles"
+set xtics 0,32,maxx
+set grid
+set key left
+plot "blake2b.data" using 1:2 with lines title "BLAKE2b"
+replot "blake2s.data" using 1:2 with lines title "BLAKE2s"
+replot "md5.data" using 1:2 with lines title "MD5"
+#pause -1 "hit return to continue"
+#set terminal png
+#set output "plotcycles.png"
+set terminal pdfcairo
+set output "plotcycles.pdf"
+replot
diff --git a/bench/makefile b/bench/makefile
new file mode 100644
index 0000000..bd3be9b
--- /dev/null
+++ b/bench/makefile
@@ -0,0 +1,16 @@
+CC=gcc
+# std to gnu99 to support inline asm
+CFLAGS=-std=gnu99 -O3 -march=native -DSUPERCOP # -DHAVE_XOP # uncomment on XOP-enabled CPUs
+FILES=amd64cpuinfo.c bench.c
+
+all:
+ $(CC) $(FILES) $(CFLAGS) ../sse/blake2b.c -o blake2b
+ $(CC) $(FILES) $(CFLAGS) ../sse/blake2s.c -o blake2s
+ $(CC) $(FILES) $(CFLAGS) md5.c -o md5 -lcrypto -lz
+ ./blake2b > blake2b.data
+ ./blake2s > blake2s.data
+ ./md5 > md5.data
+ gnuplot do.gplot
+
+clean:
+ rm -f blake2b blake2s md5 plotcycles.pdf blake2b.data blake2s.data md5.data
diff --git a/bench/md5.c b/bench/md5.c
new file mode 100644
index 0000000..c787117
--- /dev/null
+++ b/bench/md5.c
@@ -0,0 +1,21 @@
+/*
+ BLAKE2 reference source code package - benchmark tool
+
+ Written in 2012 by Samuel Neves <sneves@dei.uc.pt>
+
+ To the extent possible under law, the author(s) have dedicated all copyright
+ and related and neighboring rights to this software to the public domain
+ worldwide. This software is distributed without any warranty.
+
+ You should have received a copy of the CC0 Public Domain Dedication along with
+ this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
+*/
+#include <stddef.h>
+#include <openssl/md5.h>
+//#include "crypto_hash.h"
+
+int crypto_hash( unsigned char *out, const unsigned char *in, unsigned long long inlen )
+{
+ MD5( in, inlen, out );
+ return 0;
+}
diff --git a/bench/x86cpuinfo.c b/bench/x86cpuinfo.c
new file mode 100644
index 0000000..b549a11
--- /dev/null
+++ b/bench/x86cpuinfo.c
@@ -0,0 +1,19 @@
+/*
+ BLAKE2 reference source code package - benchmark tool
+
+ Written in 2012 by Samuel Neves <sneves@dei.uc.pt>
+
+ To the extent possible under law, the author(s) have dedicated all copyright
+ and related and neighboring rights to this software to the public domain
+ worldwide. This software is distributed without any warranty.
+
+ You should have received a copy of the CC0 Public Domain Dedication along with
+ this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
+*/
+
+unsigned long long cpucycles( void )
+{
+ unsigned long long result;
+ asm volatile( ".byte 15;.byte 49" : "=A" ( result ) );
+ return result;
+} \ No newline at end of file