Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

string_cast.cpp
Go to the documentation of this file.
1 // Copyright (c) 2018 The Dash Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #include <bench/bench.h>
6 #include <tinyformat.h>
7 #include <utilstrencodings.h>
8 
9 #include <boost/lexical_cast.hpp>
10 #include <string>
11 
12 template <typename T>
13 std::string NumberToString(T Number){
14  std::ostringstream oss;
15  oss << Number;
16  return oss.str();
17 }
18 
19 static void int_atoi(benchmark::State& state)
20 {
21  while (state.KeepRunning())
22  atoi("1");
23 }
24 
26 {
27  while (state.KeepRunning())
28  boost::lexical_cast<int>("1");
29 }
30 
32 {
33  int i{0};
34  while (state.KeepRunning())
35  itostr(++i);
36 }
37 
39 {
40  int i{0};
41  while (state.KeepRunning())
42  boost::lexical_cast<std::string>(++i);
43 }
44 
46 {
47  int i{0};
48  while (state.KeepRunning())
49  NumberToString(++i);
50 }
51 
53 {
54  int i{0};
55  while (state.KeepRunning())
56  std::to_string(++i);
57 }
58 
60 {
61  int i{0};
62  while (state.KeepRunning()) {
63  itostr(i) + itostr(i+1) + itostr(i+2) + itostr(i+3) + itostr(i+4);
64  ++i;
65  }
66 }
67 
69 {
70  int i{0};
71  while (state.KeepRunning()) {
72  boost::lexical_cast<std::string>(i) +
73  boost::lexical_cast<std::string>(i+1) +
74  boost::lexical_cast<std::string>(i+2) +
75  boost::lexical_cast<std::string>(i+3) +
76  boost::lexical_cast<std::string>(i+4);
77  ++i;
78  }
79 }
80 
82 {
83  int i{0};
84  while (state.KeepRunning()) {
86  ++i;
87  }
88 }
89 
91 {
92  int i{0};
93  while (state.KeepRunning()) {
94  std::to_string(i) + std::to_string(i+1) + std::to_string(i+2) + std::to_string(i+3) + std::to_string(i+4);
95  ++i;
96  }
97 }
98 
100 {
101  int i{0};
102  while (state.KeepRunning()) {
103  strprintf("%d|%d|%d|%d|%d", i, i+1, i+2, i+3, i+4);
104  ++i;
105  }
106 }
107 
static void strings_1_itostr(benchmark::State &state)
Definition: string_cast.cpp:31
#define strprintf
Definition: tinyformat.h:1066
bool KeepRunning()
Definition: bench.cpp:39
static void int_lexical_cast(benchmark::State &state)
Definition: string_cast.cpp:25
BENCHMARK(int_atoi)
static void strings_2_multi_to_string(benchmark::State &state)
Definition: string_cast.cpp:90
static void strings_2_multi_lexical_cast(benchmark::State &state)
Definition: string_cast.cpp:68
static void strings_1_lexical_cast(benchmark::State &state)
Definition: string_cast.cpp:38
static void strings_2_strptintf(benchmark::State &state)
Definition: string_cast.cpp:99
static void int_atoi(benchmark::State &state)
Definition: string_cast.cpp:19
std::string NumberToString(T Number)
Definition: string_cast.cpp:13
static void strings_1_to_string(benchmark::State &state)
Definition: string_cast.cpp:52
static void strings_2_multi_numberToString(benchmark::State &state)
Definition: string_cast.cpp:81
static void strings_1_numberToString(benchmark::State &state)
Definition: string_cast.cpp:45
std::string itostr(int n)
int atoi(const std::string &str)
static void strings_2_multi_itostr(benchmark::State &state)
Definition: string_cast.cpp:59
Released under the MIT license