OpenCog Framework  Branch: master, revision 6f0b7fc776b08468cf1b74aa9db028f387b4f0c0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
AtomSpaceBenchmark.h
Go to the documentation of this file.
1 #ifndef _OPENCOG_AS_BENCHMARK_H
2 #define _OPENCOG_AS_BENCHMARK_H
3 
4 #include <random>
5 #include <boost/tuple/tuple.hpp>
6 
7 #include <opencog/util/mt19937ar.h>
8 
11 // #undef HAVE_CYTHON
12 // #undef HAVE_GUILE
13 
14 using boost::tuple;
15 
16 namespace opencog
17 {
18 
19 typedef boost::tuple<clock_t,clock_t> timepair_t;
20 
21 class PythonEval;
22 class SchemeEval;
23 
25 {
26  // size of AtomSpace, time taken for operation, rss memory max
27  typedef boost::tuple<size_t,clock_t,long> record_t;
28 
29 
30  struct TimeStats {
31  clock_t t_total;
32  clock_t t_max;
33  clock_t t_min;
34  clock_t t_mean;
35  clock_t t_std;
36  long t_N;
37  TimeStats(const std::vector<record_t>& records);
38  void print();
39  };
40 
41 
42  void recordToFile(std::ofstream& file, const record_t record) const;
43 
45 
50 
51  float maxSize;
52 
55 #if HAVE_GUILE
57 #endif
58 #if HAVE_CYTHON
60 #endif
61 
62  MT19937RandGen* rng;
63 
64  std::default_random_engine randgen;
65  std::poisson_distribution<unsigned> *prg;
66 
69 
70  clock_t makeRandomNode(const std::string& s);
71  clock_t makeRandomLink();
72 
73  long getMemUsage();
74  int counter;
75 
76  std::string memoize_or_compile(std::string);
77 
78  std::vector<std::string> methodNames;
79 
80 public:
81  unsigned int Nreps;
82  unsigned int Nloops;
83  bool memoize;
84  bool compile;
86  bool saveToFile;
88  bool doStats;
90  unsigned long randomseed;
91 
93 #ifdef HAVE_GUILE
95 #endif
96 #ifdef HAVE_CYTHON
98 #endif
99  };
101 
105  std::vector< BMFn > methodsToTest;
106 
108  long atomCount;
109 
111  void printTypeSizes();
112  size_t estimateOfAtomSize(Handle h);
113 
116 
117  void setMethod(std::string method);
118  void showMethods();
119  void startBenchmark(int numThreads=1);
120  void doBenchmark(const std::string& methodName, BMFn methodToCall);
121 
122  void buildAtomSpace(long atomspaceSize=(1 << 16), float percentLinks = 0.1,
123  bool display = true);
125  void setTestAllMethods() { setMethod("all"); }
126 
131 
136 
137  // Get and set TV and AV
138  float chanceUseDefaultTV; // if set, this will use default TV for new atoms and bm_setTruthValue
141 
142 #ifdef ZMQ_EXPERIMENT
143  timepair_t bm_getTruthValueZmq();
144 #endif
145 };
146 
147 } // namespace opencog
148 
149 #endif //_OPENCOG_AS_BENCHMARK_H
std::poisson_distribution< unsigned > * prg
std::string memoize_or_compile(std::string)
std::vector< std::string > methodNames
void recordToFile(std::ofstream &file, const record_t record) const
bool showTypeSizes
number of nodes to build atomspace with before testing
std::vector< BMFn > methodsToTest
void buildAtomSpace(long atomspaceSize=(1<< 16), float percentLinks=0.1, bool display=true)
boost::tuple< size_t, clock_t, long > record_t
unsigned long UUID
UUID == Universally Unique Identifier.
Definition: Handle.h:46
timepair_t(AtomSpaceBenchmark::* BMFn)()
void setMethod(std::string method)
AtomSpace * asp
never make the atomspace bigger than this while building it
void startBenchmark(int numThreads=1)
clock_t makeRandomNode(const std::string &s)
std::default_random_engine randgen
TimeStats(const std::vector< record_t > &records)
unsigned short Type
type of Atoms, represented as short integer (16 bits)
Definition: types.h:40
void doBenchmark(const std::string &methodName, BMFn methodToCall)
boost::tuple< clock_t, clock_t > timepair_t