-fix bugs
[oweals/gnunet.git] / src / scalarproduct / perf_scalarproduct.sh
1 #!/bin/bash
2 # Computes a simple scalar product, with configurable vector size.
3 #
4 # Some results:
5 # SIZE   TIME-H(s)  TIME-O(s)
6 #  25     10
7 #  50     17
8 # 100     32          39
9 # 200                 77
10 #
11 #
12 # Configure benchmark size:
13 SIZE=400
14 #
15 # Construct input vectors:
16 INPUTALICE="-k CCC -e '"
17 INPUTBOB="-k CCC -e '"
18 for X in `seq 1 $SIZE`
19 do
20   INPUTALICE="${INPUTALICE}A${X},$X;"
21   INPUTBOB="${INPUTBOB}A${X},$X;"
22 done
23 INPUTALICE="${INPUTALICE}BC,-20000;RO,1000;FL,100;LOL,24;'"
24 INPUTBOB="${INPUTBOB}AB,10;RO,3;FL,3;LOL,-1;'"
25
26 # necessary to make the testing prefix deterministic, so we can access the config files
27 PREFIX=/tmp/test-scalarproduct`date +%H%M%S`
28
29 # where can we find the peers config files?
30 CFGALICE="-c $PREFIX/0/config"
31 CFGBOB="-c $PREFIX/1/config"
32
33 # launch two peers in line topology non-interactively
34 #
35 # interactive mode would terminate the test immediately
36 # because the rest of the script is already in stdin,
37 # thus redirecting stdin does not suffice)
38 GNUNET_FORCE_LOG=';;;;ERROR'
39 GNUNET_TESTING_PREFIX=$PREFIX ../testbed/gnunet-testbed-profiler -n -c test_scalarproduct.conf -p 2 &
40 PID=$!
41 # sleep 1 is too short on most systems, 2 works on most, 5 seems to be safe
42 echo "Waiting for peers to start..."
43 sleep 5
44 # get Bob's peer ID, necessary for Alice
45 PEERIDBOB=`gnunet-peerinfo -qs $CFGBOB`
46
47 echo "Running problem of size $SIZE"
48 gnunet-scalarproduct $CFGBOB $INPUTBOB &
49 time RESULT=`gnunet-scalarproduct $CFGALICE $INPUTALICE -p $PEERIDBOB`
50 gnunet-statistics $CFGALICE -s core | grep "bytes encrypted"
51 gnunet-statistics $CFGBOB -s core | grep "bytes encrypted"
52
53 echo "Terminating testbed..."
54 # terminate the testbed
55 kill $PID
56