Lolly 1.4.28
Loading...
Searching...
No Matches
Namespaces | Functions
numeral_bench.cpp File Reference
#include "file.hpp"
#include "lolly/data/numeral.hpp"
#include <nanobench.h>
Include dependency graph for numeral_bench.cpp:

Go to the source code of this file.

Namespaces

namespace  lolly
 

Functions

void lolly::init_tbox ()
 
int main ()
 

Detailed Description

Benchmark for converter between numeral and string

Author
jingkaimori
Date
2024

Definition in file numeral_bench.cpp.

Function Documentation

◆ main()

int main ( )

Definition at line 19 of file numeral_bench.cpp.

19 {
21 ankerl::nanobench::Bench bench;
22#ifdef OS_WASM
23 bench.minEpochIterations (2000);
24#else
25 bench.minEpochIterations (400000);
26#endif
27
28 string hex_string;
29 for (int d= 1; d < 6; d++) {
30 hex_string << ('a' + d % 6);
31 bench.complexityN (d);
32 bench.run ("convert hexadecimal string to int",
33 [&] { from_hex (hex_string); });
34 int hex_number= (0x1 << ((d + 1) * 4)) - 1;
35 bench.run ("convert signed int to hexadecimal string",
36 [&] { to_Hex (hex_number); });
37 bench.run ("convert unsigned int to hexadecimal string",
38 [&] { as_hexadecimal (hex_number, d); });
39 }
40 string content= string_load (url_pwd () * "LICENSE");
41 ankerl::nanobench::Bench bench2;
42 bench2.relative (true)
43 .minEpochTime (std::chrono::milliseconds (10))
44 .run ("convert document to hexadecimal string, legacy",
45 [&] {
46 string result;
47 for (int i= 0; i < N (content); i++)
48 result << as_hexadecimal ((unsigned char) content[i], 2);
49 })
50 .run (
51 "convert document to hexadecimal string, using binary_to_hexadecimal",
52 [&] { string result= binary_to_hexadecimal (content); });
53}
The list class represents a linked list.
Definition list.hpp:48
string string_load(url u)
Definition file.cpp:440
static ankerl::nanobench::Bench bench
string binary_to_hexadecimal(string bin)
Converts a binary stream to its hexadecimal represention.
Definition numeral.cpp:313
string as_hexadecimal(int i, int len)
Converts an unsigned integer to a hexadecimal string with a fixed length.
Definition numeral.cpp:247
int N(lolly_tree< T > t)
static const char * hex_string
Definition numeral.cpp:31
int from_hex(string s)
Converts a hexadecimal string to an integer.
Definition numeral.cpp:214
string to_Hex(int32_t i)
Definition numeral.cpp:174
void init_tbox()
url url_pwd()
Definition url.cpp:326