Lolly 1.4.28
Loading...
Searching...
No Matches
analyze_bench.cpp
Go to the documentation of this file.
1/** \file analyze_bench.cpp
2 * \copyright GPLv3
3 * \details Benchmark for string algorithms
4 * \author jingkaimori
5 * \date 2024
6 */
7
8#include "analyze.hpp"
9#include "sys_utils.hpp"
10#include <nanobench.h>
11
12void
14 ankerl::nanobench::Bench bench;
15 bench.relative (true).minEpochIterations (1000).run (
16 c_string (base_name * " by append"), [&] {
17 string res;
18 int lth= N (str);
19 for (size_t i= 0; i < lth; i++) {
20 res << str[i];
21 }
22 });
23 bench.run (c_string (base_name * " by concat"), [&] {
24 string res;
25 int lth= N (str);
26 for (size_t i= 0; i < lth; i++) {
27 res= str[i] * res;
28 }
29 });
30 bench.run (c_string (base_name * " by recompose"),
31 [&] { recompose (str, ""); });
32}
33
34int
35main () {
37 bench_string_join ("join regular string",
38 array<string> ("long string", "short", "", "<#ABCD>"));
39 bench_string_join ("join two string", array<string> ("long string", "short"));
40 bench_string_join ("join empty ones", array<string> (5));
41
42 ankerl::nanobench::Rng rng;
43 int total= 20;
45 for (int i= 0; i < total; i++) {
46 test_case << string ('!' + i, rng.bounded (30));
47 }
48 bench_string_join ("join a bunch of random string", test_case);
49
50 return 0;
51}
string recompose(array< string > a, string sep)
Definition analyze.cpp:963
int main()
void bench_string_join(string base_name, array< string > str)
int N(array< T > a)
Get the length of the array.
Definition array.hpp:170
The list class represents a linked list.
Definition list.hpp:48
static ankerl::nanobench::Bench bench
void init_tbox()