25 #include <boost/algorithm/string.hpp> 26 #include <boost/filesystem.hpp> 42 <<
"Usage bench <mode> [OPTIONS]" << endl
44 <<
" trie Trie benchmarks." << endl
46 <<
"General options:" << endl
47 <<
" -h,--help Print this help message and exit." << endl
48 <<
" -V,--version Show the version and exit." << endl
55 cout <<
"bench part of dev suite version " <<
dev::Version << endl;
75 if (!std::setlocale(LC_ALL,
""))
77 setenv(
"LC_ALL",
"C", 1);
96 StandardMap(
Alphabet _alphabet,
unsigned _count,
unsigned _minKey,
unsigned _diffKey): m_alphabet(_alphabet), m_count(_count), m_minKey(_minKey), m_diffKey(_diffKey) {}
98 vector<pair<bytes, bytes>>
make()
const 100 string const c_low =
"abcdef";
101 string const c_mid =
"@QWERTYUIOPASDFGHJKLZXCVBNM[/]^_";
104 vector<pair<bytes, bytes>> input;
105 for (
unsigned j = 0; j < m_count; ++j)
108 bytes v = randomValue(&seed);
109 input.push_back(make_pair(k, v));
122 assert(_min + _diff < 33);
123 *_seed =
sha3(*_seed);
124 unsigned l = _min + (*_seed)[31] % (_diff + 1);
126 for (
unsigned i = 0; i < l; ++i)
127 ret.push_back(_alphabet[(*_seed)[i] % _alphabet.
size()]);
133 assert(_min + _diff < 33);
134 *_seed =
sha3(*_seed);
135 unsigned l = _min + (*_seed)[31] % (_diff + 1);
141 *_seed =
sha3(*_seed);
143 return bytes(1, (*_seed)[31]);
149 int main(
int argc,
char** argv)
154 for (
int i = 1; i < argc; ++i)
156 string arg = argv[i];
157 if (arg ==
"-h" || arg ==
"--help")
159 else if (arg ==
"trie")
161 else if (arg ==
"sha3")
163 else if (arg ==
"-V" || arg ==
"--version")
169 unordered_map<string, StandardMap> maps =
176 unsigned trials = 50;
177 for (
auto const&
sm: maps)
183 auto map =
sm.second.make();
185 for (
unsigned i = 0; i < trials; ++i)
186 for (
auto const& i: map)
187 t.
insert(&i.first, &i.second);
190 cout <<
sm.first <<
": " <<
e * 1000000 <<
" us, root=" << t.
root() << endl;
195 unsigned trials = 50;
197 for (
unsigned trial = 0; trial < trials; ++trial)
200 for (
unsigned i = 0; i < 1000; ++i)
203 cout <<
"sha3 x 1000: " << t.
elapsed() / trials * 1000000 <<
"us " << endl;
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
SHA3 message digest base class.
Merkle Patricia Tree "Trie": a modifed base-16 Radix tree.
static bytes randomBytes(unsigned _min, unsigned _diff, h256 *_seed)
StandardMap(Alphabet _alphabet, unsigned _count, unsigned _minKey, unsigned _diffKey)
std::string randomWord()
Creates a random, printable, word.
std::hash for asio::adress
assert(len-trim+(2 *lenIndices)<=WIDTH)
static bytes randomWord(bytesConstRef _alphabet, unsigned _min, unsigned _diff, h256 *_seed)
vector_ref< _T > cropped(size_t _begin, size_t _count) const
static bytes randomValue(h256 *_seed)
void setDefaultOrCLocale()
int main(int argc, char **argv)
h256 const & root() const
std::vector< byte > bytes
vector< pair< bytes, bytes > > make() const
bool sha3(bytesConstRef _input, bytesRef o_output)
Calculate SHA3-256 hash of the given input and load it into the given output.
void insert(bytes const &_key, bytes const &_value)