Debian Codegraph @

tests/stringbuilder-bench.md

raw symbols SCIP
1 # Simple/stupid benchmarking
2
3 Compares the string builder and numberToString() function as provided by c++utilities
4 with std::stringstream (without reserving stringstream buffer).
5
6 The string builder is actually just a fancy syntax for std::string::reserve()
7 making its use more convenient.
8
9 ## Compile and run
10
11 eg.
12 ```
13 g++ -O3 stringbuilder-bench.cpp -o stringbuilder-bench-O3 -Wl,-rpath /lib/path -L /lib/path -lc++utilities
14 ./stringbuilder-bench-O3
15 ```
16
17 ## Results on my machine
18
19 Results with -03:
20
21 ```
22 plus operator: 00:00:19
23 stringstream: 00:00:16
24 string builder: 00:00:05
25 diff (stringstream minus string builder): 00:00:11
26 factor (stringstream / string builder): 3.2
27 ```
28
29 However, with -O0 4 times *slower*:
30
31 ```
32 plus operator: 00:00:34
33 stringstream: 00:00:23
34 string builder: 00:01:02
35 diff (stringstream minus string builder): - 00:35:31
36 factor (stringstream / string builder): 0.370968
37 ```
38
39 Still 2.42 times faster than stringstream with -O2:
40
41 ```
42 plus operator: 00:00:21
43 stringstream: 00:00:17
44 string builder: 00:00:07
45 diff (stringstream minus string builder): 00:00:10
46 factor (stringstream / string builder): 2.42857
47 ```
48
49 So this basic tests show that string builder is up to 3 times faster when using full optimization
50 and still 2 times faster when using -O2 (default under Arch Linux). However, without optimization it way
51 slower. Results with clang++ were similar.