Commit 9f605136 authored by Guillaume Melquiond's avatar Guillaume Melquiond

Improve benchmarks for example/multiprecision.

1. Output is in µs/ops.
2. The number of iterations is inversely proportional to the size of
   the arguments, to account for the inherent time complexity.
3. The compilation flags are taken from GMP, if available.
parent 41e5758e
......@@ -244,8 +244,8 @@ extract_and_test_wmp () {
echo "ok"
else
echo "execution failed!"
echo $dir/main.opt
$dir/main.opt
echo $dir/build/bench-tests
$dir/build/bench-tests
exit 1
fi
else
......
......@@ -10,6 +10,14 @@ else
endif
endif
ifdef GMP_DIR
GMPFLAGS = $(shell sed -n -e 's/^CFLAGS = \(.*\)/\1/p' $(GMP_DIR)/Makefile)
else
GMPFLAGS = -O2 -pedantic -fomit-frame-pointer
endif
CFLAGS = $(GMPFLAGS) -Wall -Wno-unused-function -g -std=c11
all: why3 extract
clean:
......@@ -33,23 +41,23 @@ extract: why3 dir cfiles
CFILES = build/uint64gmp.c build/toom.c build/div.c build/logical.c build/mul.c build/sub.c build/add.c build/compare.c build/util.c build/int32.c
tests: extract check-gmp
gcc -O2 -Wall -Wno-unused-function -g -std=c11 -pedantic tests.c $(CFILES) -I$(GMP_DIR) -Irandom -L$(GMP_LIB) -fomit-frame-pointer -mtune=haswell -march=haswell -fno-tree-vectorize -lgmp -o build/tests
gcc -O2 -Wall -Wno-unused-function -g -std=c11 -pedantic -DCOMPARE_MINI tests.c $(CFILES) -I$(GMP_DIR) -Irandom -Imini-gmp -fomit-frame-pointer -mtune=haswell -march=haswell -fno-tree-vectorize -o build/minitests
gcc $(CFLAGS) tests.c $(CFILES) -I$(GMP_DIR) -Irandom -L$(GMP_LIB) -lgmp -o build/tests
gcc $(CFLAGS) -DCOMPARE_MINI tests.c $(CFILES) -I$(GMP_DIR) -Irandom -Imini-gmp -o build/minitests
./build/tests
./build/minitests
bench-tests: extract
gcc -O2 -Wall -Wno-unused-function -g -std=c11 tests.c $(CFILES) -Ibench-include -Irandom -fomit-frame-pointer -fno-tree-vectorize -lgmp -o build/bench-tests
gcc $(CFLAGS) tests.c $(CFILES) -Ibench-include -Irandom -lgmp -o build/bench-tests
build/why3%bench: extract check-gmp
gcc -O2 -Wall -Wno-unused-function -g -std=c11 -DTEST_WHY3 -DTEST_`echo $* | tr [:lower:] [:upper:]` tests.c $(CFILES) -I$(GMP_DIR) -Irandom -L$(GMP_LIB) -fomit-frame-pointer -mtune=haswell -march=haswell -fno-tree-vectorize -lgmp -o $@
gcc $(CFLAGS) -DTEST_WHY3 -DTEST_`echo $* | tr [:lower:] [:upper:]` tests.c $(CFILES) -I$(GMP_DIR) -Irandom -L$(GMP_LIB) -lgmp -o $@
build/gmp%bench: extract check-gmp
gcc -O2 -Wall -Wno-unused-function -g -std=c11 -DTEST_GMP -DTEST_`echo $* | tr [:lower:] [:upper:]` tests.c $(CFILES) -I$(GMP_DIR) -Irandom -L$(GMP_LIB) -fomit-frame-pointer -mtune=haswell -march=haswell -fno-tree-vectorize -lgmp -o $@
gcc $(CFLAGS) -DTEST_GMP -DTEST_`echo $* | tr [:lower:] [:upper:]` tests.c $(CFILES) -I$(GMP_DIR) -Irandom -L$(GMP_LIB) -lgmp -o $@
build/minigmp%bench: extract
gcc -O2 -Wall -Wno-unused-function -g -std=c11 -DTEST_MINIGMP -DTEST_`echo $* | tr [:lower:] [:upper:]` tests.c $(CFILES) -I$(GMP_DIR) -Imini-gmp -Irandom -fomit-frame-pointer -mtune=haswell -march=haswell -fno-tree-vectorize -o $@
gcc $(CFLAGS) -DTEST_MINIGMP -DTEST_`echo $* | tr [:lower:] [:upper:]` tests.c $(CFILES) -I$(GMP_DIR) -Imini-gmp -Irandom -o $@
alltests: tests build/why3addbench build/why3mulbench build/why3toombench build/why3divbench build/gmpaddbench build/gmpmulbench build/gmptoombench build/gmpdivbench build/minigmpaddbench build/minigmpmulbench build/minigmpdivbench build/minigmptoombench
......
......@@ -126,14 +126,14 @@ set xlabel ""
set xlabel font "" textcolor lt -1 norotate
set x2label ""
set x2label font "" textcolor lt -1 norotate
set xrange [ 200.000 : 600.000 ] noreverse nowriteback
set x2range [ 210.000 : 570.000 ] noreverse nowriteback
set xrange [ * : * ] noreverse nowriteback
set x2range [ * : * ] noreverse nowriteback
set ylabel ""
set ylabel font "" textcolor lt -1 rotate by -270
set y2label ""
set y2label font "" textcolor lt -1 rotate by -270
set yrange [ -0.100000 : 0.00000 ] noreverse nowriteback
set y2range [ -0.0984999 : -0.0110689 ] noreverse nowriteback
set yrange [ * : * ] noreverse nowriteback
set y2range [ * : * ] noreverse nowriteback
set zlabel ""
set zlabel font "" textcolor lt -1 norotate
set zrange [ * : * ] noreverse nowriteback
......
......@@ -43,9 +43,9 @@ void mpn_dump(mp_ptr ap, mp_size_t an) {
}
void init_valid (mp_ptr ap, mp_ptr bp, mp_size_t an, mp_size_t bn) {
for (int i = 0; i <= an; i++)
for (int i = 0; i < an; i++)
ap[i] = genrand64_int64();
for (int i = 0; i <= bn; i++)
for (int i = 0; i < bn; i++)
bp[i] = genrand64_int64();
while (bp[bn-1]==0)
bp[bn-1] = genrand64_int64();
......@@ -56,6 +56,7 @@ int main () {
mp_ptr ap, bp, rp, refp, rq, rr, refq, refr;
mp_size_t max_n, max_add, max_mul, max_toom, max_div, an, bn, rn;
#ifdef BENCH
int nb, nb_iter;
struct timeval begin, end;
double elapsed;
#endif
......@@ -71,7 +72,11 @@ int main () {
//gmp_randseed_ui(rands, 42);
/* Re-interpret reps argument as a size argument. */
#ifdef BENCH
init_genrand64(0);
#else
init_genrand64((unsigned long long)time(NULL));
#endif
max_n = 1000;
max_add = 50;
max_mul = 20;
......@@ -90,7 +95,7 @@ int main () {
#ifdef TEST_ADD
#ifdef BENCH
printf ("#an bn t(s)\n");
printf ("#an bn t(µs)\n");
#endif
for (an = 2; an <= max_add; an += 1)
{
......@@ -99,10 +104,12 @@ int main () {
init_valid (ap, bp, an, bn);
#ifdef BENCH
elapsed = 0;
for (int iter = 0; iter != 1000; ++iter) {
nb_iter = 1000;
for (int iter = 0; iter != nb_iter; ++iter) {
init_valid (ap, bp, an, bn);
nb = 10000 / an;
gettimeofday(&begin, NULL);
for (int i = 0; i != 100; ++i)
for (int i = 0; i != nb; ++i)
{
#endif
......@@ -117,10 +124,11 @@ int main () {
}
gettimeofday(&end, NULL);
elapsed +=
(end.tv_sec - begin.tv_sec)
+ ((end.tv_usec - begin.tv_usec)/1000000.0);
(end.tv_sec - begin.tv_sec) * 1000000.0
+ (end.tv_usec - begin.tv_usec);
}
printf ("%d %d %f\n", an, bn, elapsed);
elapsed = elapsed / (nb * nb_iter);
printf ("%d %d %g\n", an, bn, elapsed);
if (an==bn)
printf ("\n"); //for gnuplot
#endif
......@@ -155,7 +163,7 @@ int main () {
#endif
#ifdef TEST_MUL
#ifdef BENCH
printf ("#an bn t(s)\n");
printf ("#an bn t(µs)\n");
#endif
for (an = 2; an <= max_mul; an += 1)
{
......@@ -164,10 +172,12 @@ int main () {
init_valid (ap, bp, an, bn);
#ifdef BENCH
elapsed = 0;
for (int iter = 0; iter != 500; ++iter) {
nb_iter = 500;
for (int iter = 0; iter != nb_iter; ++iter) {
init_valid (ap, bp, an, bn);
gettimeofday(&begin, NULL);
for (int i = 0; i != 100; ++i)
nb = 5000 / an;
for (int i = 0; i != nb; ++i)
{
#endif
#if defined(TEST_GMP) || defined(TEST_MINIGMP)
......@@ -181,10 +191,11 @@ int main () {
}
gettimeofday(&end, NULL);
elapsed +=
(end.tv_sec - begin.tv_sec)
+ ((end.tv_usec - begin.tv_usec)/1000000.0);
(end.tv_sec - begin.tv_sec) * 1000000.0
+ (end.tv_usec - begin.tv_usec);
}
printf ("%d %d %f\n", an, bn, elapsed);
elapsed = elapsed / (nb * nb_iter);
printf ("%d %d %g\n", an, bn, elapsed);
if (an==bn)
printf ("\n"); //for gnuplot
#endif
......@@ -210,7 +221,7 @@ int main () {
#ifdef TEST_TOOM
#ifdef BENCH
printf ("#an bn t(s)\n");
printf ("#an bn t(µs)\n");
#endif
for (bn = 35; bn <= max_toom; bn += 2)
......@@ -221,10 +232,12 @@ int main () {
init_valid (ap, bp, an, bn);
#ifdef BENCH
elapsed = 0;
for (int iter = 0; iter != 500; ++iter) {
nb_iter = 500;
for (int iter = 0; iter != nb_iter; ++iter) {
init_valid (ap, bp, an, bn);
gettimeofday(&begin, NULL);
for (int i = 0; i != 100; ++i)
nb = 5000 / bn;
for (int i = 0, maxi = nb; i != maxi; ++i)
{
#endif
#if defined(TEST_GMP) || defined(TEST_MINIGMP)
......@@ -238,10 +251,11 @@ int main () {
}
gettimeofday(&end, NULL);
elapsed +=
(end.tv_sec - begin.tv_sec)
+ ((end.tv_usec - begin.tv_usec)/1000000.0);
(end.tv_sec - begin.tv_sec) * 1000000.0
+ (end.tv_usec - begin.tv_usec);
}
printf ("%d %d %f\n", an, bn, elapsed);
elapsed = elapsed / (nb * nb_iter);
printf ("%d %d %g\n", an, bn, elapsed);
if (an==bn)
printf ("\n"); //for gnuplot
#endif
......@@ -267,7 +281,7 @@ int main () {
#ifdef TEST_DIV
#ifdef BENCH
printf ("#an bn t(s)\n");
printf ("#an bn t(µs)\n");
#endif
for (an = 2; an <= max_div; an += 1)
{
......@@ -280,13 +294,15 @@ int main () {
#ifdef BENCH
elapsed = 0;
for (int iter = 0; iter != 1000; ++iter) {
nb_iter = 1000;
for (int iter = 0; iter != nb_iter; ++iter) {
init_valid (ap, bp, an, bn);
#ifdef TEST_MINIGMP
mpn_copyi(refr, ap, an);
#endif
gettimeofday(&begin, NULL);
for (int i = 0; i != 100; ++i)
nb = 1500 / an;
for (int i = 0; i != nb; ++i)
{
#endif
#ifdef TEST_GMP
......@@ -303,10 +319,11 @@ int main () {
}
gettimeofday(&end, NULL);
elapsed +=
(end.tv_sec - begin.tv_sec)
+ ((end.tv_usec - begin.tv_usec)/1000000.0);
(end.tv_sec - begin.tv_sec) * 1000000.0
+ (end.tv_usec - begin.tv_usec);
}
printf ("%d %d %f\n", an, bn, elapsed);
elapsed = elapsed / (nb * nb_iter);
printf ("%d %d %g\n", an, bn, elapsed);
if (an==bn)
printf ("\n"); //for gnuplot
#endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment