Belofte version 2.1.8
A promising chess program using the UCI or Winboard interface
util.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------+
2 * File: util.h
3 * Project: part of belofte - A Promising Chess Program
4 * Author: yves
5 * SPDX-License-Identifier: GPL-2.0-only
6+----------------------------------------------------------------------*/
7
8#if !defined(UTIL_H)
9#define UTIL_H
10
11/**
12 * Helper class for measuring execution time for functions
13 * Call ClockStart and ClockEnd at end of execution
14 * If getDuration is being called without ClockEnd, it will return
15 * elapsed time but continue counting
16 */
18public:
20 virtual ~TimedExecution() = default;
21
22 std::string getDuration() const;
23 long long getDurationMicroSec() const;
24
25protected:
26 void ClockStart();
27 void ClockEnd();
28 long long getDurationSec() const;
29 long long getDurationMilliSec() const;
30
31private:
32 bool m_isEnded = false;
33#if defined(CHRONO_MISSING)
34 struct timeval execution_start;
35 struct timeval execution_end;
36#else
37 std::chrono::high_resolution_clock::time_point execution_start;
38 std::chrono::high_resolution_clock::time_point execution_end;
39#endif
40};
41
42//-----------------------------------------------------------------------
43
44namespace belofte {
45
46 typedef std::vector<std::string> stringList;
47
48 stringList const stringSplit(std::string src, std::string const& delim);
49 std::pair<std::string, std::string> decompose(std::string const& src,
50 std::string const& delim);
51 std::string to_string(int32_t value);
52 std::string to_string(int64_t value);
53 std::string alltrim(std::string s, std::string const& delim = " ");
54 bool is_number(std::string const& s);
55 int getRandomInt(int const nCeil);
56 int getRandomRange(int const nStart, int const nMax);
57 std::string getRCname(std::string const& basename);
58 int positionParamIndex(stringList const& param,
59 std::string const& find);
60 int positionParamValue(stringList const& param,
61 std::string const& find, unsigned long const nOffSet = 0);
62 std::string currentDate();
63 std::string scoreAsStr(long const sc);
64 std::string prettyTime(long const t);
65}
66
67#endif // defined UTIL_H
68
69// eof
Helper class for measuring execution time for functions Call ClockStart and ClockEnd at end of execut...
Definition util.h:17
long long getDurationSec() const
Definition util.cpp:105
void ClockEnd()
Definition util.cpp:37
std::string getDuration() const
Definition util.cpp:47
TimedExecution()
implementation of timing functions
Definition util.cpp:17
long long getDurationMilliSec() const
Definition util.cpp:83
virtual ~TimedExecution()=default
void ClockStart()
Definition util.cpp:27
long long getDurationMicroSec() const
Definition util.cpp:61
Allow index mapper for char values of piece into int in 1-12 range to reduce space and easy initialis...
Definition eval.h:43