Lolly 1.4.28
Loading...
Searching...
No Matches
Functions
analyze_bench.cpp File Reference
#include "analyze.hpp"
#include "sys_utils.hpp"
#include <nanobench.h>
Include dependency graph for analyze_bench.cpp:

Go to the source code of this file.

Functions

void bench_string_join (string base_name, array< string > str)
 
int main ()
 

Detailed Description

Benchmark for string algorithms

Author
jingkaimori
Date
2024

Definition in file analyze_bench.cpp.

Function Documentation

◆ bench_string_join()

void bench_string_join ( string base_name,
array< string > str )

Definition at line 13 of file analyze_bench.cpp.

13 {
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}
string recompose(array< string > a, string sep)
Definition analyze.cpp:963
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

◆ main()

int main ( )

Definition at line 35 of file analyze_bench.cpp.

35 {
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}
void bench_string_join(string base_name, array< string > str)
void init_tbox()