OpenCog Framework  Branch: master, revision 6f0b7fc776b08468cf1b74aa9db028f387b4f0c0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
atomspace_bm.cc
Go to the documentation of this file.
1 
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <unistd.h>
5 
6 #include <cstdlib>
7 
8 #include "AtomSpaceBenchmark.h"
9 
10 using namespace std;
11 
12 int main(int argc, char** argv)
13 {
14  const char* benchmark_desc = "Benchmark tool OpenCog AtomSpace\n"
15  "Usage: atomspace_bm [-m <method>] [options]\n"
16  "-t \tPrint information on type sizes\n"
17  "-A \tBenchmark all methods\n"
18  "-X \tTest the AtomTable API\n"
19  "-g \tTest the Scheme API\n"
20  "-M \tMemoize Scheme expressions\n"
21  "-C \tCompile Scheme expressions\n"
22  "-c \tTest the Python API\n"
23  "-m <methodname>\tMethod to benchmark\n"
24  "-l \tList valid method names to benchmark\n"
25  "-n <int> \tHow many times to call the method in the measurement loop\n"
26  " \t(default: 100000)\n"
27  "-r <int> \tLooping count; how many times a python/scheme operation is looped\n"
28  " \t(default: 1)\n"
29  "-R <int> \tUse specific randomseed; useful for benchmark comparisons\n"
30  " \t(default: time(NULL))\n"
31  "-S <int> \tHow many random atoms to add after each measurement\n"
32  " \t(default: 0)\n"
33  "-- Build test data --\n"
34  "-p <float> \tSet the connection probability or coordination number\n"
35  " \t(default: 0.2)\n"
36  " \t(-p impact behaviour of -S too)\n"
37  "-s <int> \tSet how many atoms are created (default: 256K)\n"
38  "-d <float> \tChance of using default truth value (default: 0.8)\n"
39  "-- Saving data --\n"
40  "-k \tCalculate stats (warning, this will affect rss memory reporting)\n"
41  "-f \tSave a csv file with records for every repeated event\n"
42  "-i <int> \tSet interval of data to save\n";
43 
44  int c;
45 
46  if (argc==1) {
47  fprintf (stderr, "%s", benchmark_desc);
48  return 0;
49  }
50  opencog::AtomSpaceBenchmark benchmarker;
51 
52  opterr = 0;
54 
55  while ((c = getopt (argc, argv, "tAXgMCcm:ln:r:R:S:p:s:d:kfi:")) != -1) {
56  switch (c)
57  {
58  case 't':
59  benchmarker.showTypeSizes = true;
60  break;
61  case 'A':
62  benchmarker.buildTestData = true;
63  benchmarker.setTestAllMethods();
64  break;
65  case 'X':
67  break;
68  case 'g':
69 #ifdef HAVE_GUILE
71 #else
72  cerr << "Fatal Error: Benchmark not compiled with scheme support!" << endl;
73  exit(1);
74 #endif
75  break;
76  case 'C':
77  benchmarker.compile = true;
78  break;
79  case 'M':
80  benchmarker.memoize = true;
81  break;
82  case 'c':
83 #ifdef HAVE_CYTHON
85 #else
86  cerr << "Fatal Error: Benchmark not compiled with cython support!" << endl;
87  exit(1);
88 #endif
89  break;
90  case 'm':
91  benchmarker.buildTestData = true;
92  benchmarker.setMethod(optarg);
93  break;
94  case 'l':
95  benchmarker.showMethods();
96  exit(0);
97  break;
98  case 'n':
99  benchmarker.Nreps = (unsigned int) atoi(optarg);
100  break;
101  case 'r':
102  benchmarker.Nloops = (unsigned int) atoi(optarg);
103  break;
104  case 'R': {
105  char* last_arg_char = optarg + strlen(optarg);
106  benchmarker.randomseed = (unsigned long) std::strtoul(optarg,
107  &last_arg_char, 10); }
108  break;
109  case 'S':
110  benchmarker.sizeIncrease = atoi(optarg);
111  break;
112  case 'p':
113  benchmarker.percentLinks = atof(optarg);
114  break;
115  case 's':
116  benchmarker.atomCount = (long) atof(optarg);
117  break;
118  case 'd':
119  benchmarker.chanceUseDefaultTV = atof(optarg);
120  break;
121  case 'k':
122  benchmarker.doStats = true;
123  break;
124  case 'f':
125  benchmarker.saveToFile = true;
126  break;
127  case 'i':
128  benchmarker.saveInterval = atoi(optarg);
129  break;
130  case '?':
131  fprintf (stderr, "%s", benchmark_desc);
132  return 0;
133  default:
134  fprintf (stderr, "Unknown option %c ", optopt);
135  abort ();
136  }
137  }
138 
139  if (true
140 #ifdef HAVE_GUILE
142 #endif // HAVE_GUILE
143 #ifdef HAVE_CYTHON
145 #endif // HAVE_CYTHON
146  )
147  {
148  if (1 != benchmarker.Nloops)
149  {
150  cerr << "Fatal Error: the atomspace tests do not support looping\n";
151  exit(-1);
152  }
153  if (true == benchmarker.memoize)
154  {
155  cerr << "Fatal Error: memoization not supported for atomspace tests\n";
156  exit(-1);
157  }
158  }
159 
160 #ifdef HAVE_CYTHON
161  if ((true == benchmarker.compile)
163  {
164  cerr << "Fatal Error: Python does not have a compiler\n";
165  exit(-1);
166  }
167 #endif
168 
169 #ifdef HAVE_GUILE
171  {
172  if (true == benchmarker.memoize and true == benchmarker.compile)
173  {
174  cerr << "Fatal Error: Can compile or memoize, but not both!\n";
175  exit(-1);
176  }
177  }
178 #endif // HAVE_GUILE
179 
180  benchmarker.startBenchmark();
181  return 0;
182 }
bool showTypeSizes
number of nodes to build atomspace with before testing
void setMethod(std::string method)
void startBenchmark(int numThreads=1)
int main(int argc, char **argv)
Definition: atomspace_bm.cc:12