xref: /aosp_15_r20/external/rappor/analysis/cpp/run.sh (revision 2abb31345f6c95944768b5222a9a5ed3fc68cc00)
1#!/bin/bash
2#
3# Usage:
4#   ./run.sh <function name>
5
6set -o nounset
7set -o pipefail
8set -o errexit
9
10# Call gcc with the flags we like.
11# NOTE: -O3 does a lot for fast_em.  (More than 5x speedup over unoptimized)
12
13cpp-compiler() {
14  g++ -Wall -Wextra -O3 "$@"
15  #clang++ -Wall -Wextra -O3 "$@"
16}
17
18build-find-cliques() {
19  mkdir -p _tmp
20  # C++ 11 for unordered_{map,set}
21  cpp-compiler -std=c++0x -o _tmp/find_cliques find_cliques.cc
22}
23
24find-cliques() {
25  _tmp/find_cliques "$@"
26}
27
28test-bad-edge() {
29  # Edge should go from lesser partition number to greater
30  find-cliques <<EOF
31num_partitions 3
32ngram_size 2
33edge 1.ab 0.cd
34EOF
35}
36
37test-bad-size() {
38  # Only support n =2 now
39  find-cliques <<EOF
40num_partitions 3
41ngram_size 3
42edge 0.ab 1.cd
43EOF
44}
45
46demo() {
47  local graph=${1:-testdata/graph1.txt}
48  build-find-cliques
49
50  time cat $graph | find-cliques
51}
52
53get-lint() {
54  mkdir -p _tmp
55  wget --directory _tmp \
56    http://google-styleguide.googlecode.com/svn/trunk/cpplint/cpplint.py
57  chmod +x _tmp/cpplint.py
58}
59
60lint() {
61  _tmp/cpplint.py find_cliques.cc fast_em.cc
62}
63
64build-fast-em() {
65  mkdir -p _tmp
66  local out=_tmp/fast_em
67
68  cpp-compiler -o $out fast_em.cc
69  ls -l $out
70}
71
72fast-em() {
73  build-fast-em
74  time _tmp/fast_em "$@"
75}
76
77"$@"
78