@@ -17,12 +17,12 @@ without forcing a structured type on the user.
17
17
typedef const char * stx_t ;
18
18
```
19
19
20
- A * strick* is just a normal ` char* ` , and can be passed to ` <string.h> ` functions.
21
- Metadata, invisible to the user, are set in a prefix header :
20
+ A * strick* looks like a normal ` char* ` and can be passed to ` <string.h> ` functions.
21
+ Metadata are hidden in a prefix header :
22
22
23
23
![ schema] ( assets/schema.png )
24
24
25
- Header and string occupy a ** continuous** block of memory,
25
+ Header and string occupy a ** continuous** memory block ,
26
26
avoiding the further indirection of ` {len,*str} ` schemes.
27
27
This technique is notably used in [ SDS] ( https://github.com/antirez/sds ) ,
28
28
now part of [ Redis] ( https://github.com/redis/redis ) .
@@ -35,16 +35,16 @@ now part of [Redis](https://github.com/redis/redis).
35
35
#include " stx.h"
36
36
37
37
int main () {
38
- stx_t s = stx_from("Stricks ");
39
- stx_append (&s, " or treats !");
38
+ stx_t s = stx_from("Treats or... ");
39
+ stx_append (&s, "Stricks !");
40
40
printf(s);
41
41
return 0;
42
42
}
43
43
```
44
44
45
45
```
46
46
$ gcc app.c stx -o app && ./app
47
- Stricks or treats !
47
+ Treats or...Stricks !
48
48
```
49
49
50
50
#### Sample
@@ -102,43 +102,45 @@ split and join
102
102
```
103
103
104
104
C++ benchmark :
105
- (depends on * libbenchmark-dev* )
105
+ (depends on * libbenchmark-dev* )
106
106
` make && make benchcpp `
107
107
108
+ On Thinkpad T420 with ` cpupower frequency-set --governor performance ` :
109
+
108
110
```
109
111
------------------------------------------------------------
110
112
Benchmark Time CPU Iterations
111
113
------------------------------------------------------------
112
- SDS_from/8 33 ns 33 ns 21195861
113
- SDS_from/64 29 ns 29 ns 23880855
114
- SDS_from/512 29 ns 29 ns 23829329
115
- SDS_from/4096 254 ns 254 ns 2749531
116
- SDS_from/32768 2605 ns 2604 ns 271881
117
- STX_from/8 21 ns 21 ns 33658632
118
- STX_from/64 33 ns 33 ns 21016625
119
- STX_from/512 33 ns 33 ns 21096349
120
- STX_from/4096 171 ns 171 ns 4090580
121
- STX_from/32768 1469 ns 1469 ns 475015
122
- SDS_append/8 14 ns 14 ns 48464522
123
- SDS_append/64 12 ns 12 ns 58368923
124
- SDS_append/512 12 ns 12 ns 58239215
125
- SDS_append/4096 1605 ns 1605 ns 432650
126
- SDS_append/32768 12934 ns 12925 ns 51349
127
- STX_append/8 9 ns 9 ns 74110105
128
- STX_append/64 9 ns 9 ns 76000411
129
- STX_append/512 9 ns 9 ns 75701288
130
- STX_append/4096 935 ns 935 ns 824923
131
- STX_append/32768 7011 ns 7007 ns 93732
132
- SDS_split_join/8 13 us 13 us 53062
133
- SDS_split_join/64 42 us 42 us 16840
134
- SDS_split_join/512 261 us 261 us 2684
135
- SDS_split_join/4096 2037 us 2035 us 343
136
- SDS_split_join/32768 17104 us 17102 us 41
137
- STX_split_join/8 5 us 5 us 154199
138
- STX_split_join/64 6 us 6 us 116075
139
- STX_split_join/512 16 us 16 us 44482
140
- STX_split_join/4096 108 us 108 us 6451
141
- STX_split_join/32768 1638 us 1638 us 422
114
+ SDS_from/8 33 ns 33 ns 21363820
115
+ SDS_from/64 29 ns 29 ns 23942248
116
+ SDS_from/512 29 ns 29 ns 23982314
117
+ SDS_from/4096 271 ns 271 ns 2585840
118
+ SDS_from/32768 2738 ns 2738 ns 255377
119
+ STX_from/8 21 ns 21 ns 33747602
120
+ STX_from/64 20 ns 20 ns 35346041
121
+ STX_from/512 20 ns 20 ns 35170533
122
+ STX_from/4096 170 ns 170 ns 4104671
123
+ STX_from/32768 1462 ns 1462 ns 467821
124
+ SDS_append/8 14 ns 14 ns 48313704
125
+ SDS_append/64 12 ns 12 ns 57793801
126
+ SDS_append/512 12 ns 12 ns 57707384
127
+ SDS_append/4096 1617 ns 1617 ns 426224
128
+ SDS_append/32768 13175 ns 13174 ns 50770
129
+ STX_append/8 9 ns 9 ns 72565984
130
+ STX_append/64 9 ns 9 ns 74644788
131
+ STX_append/512 10 ns 10 ns 75197471
132
+ STX_append/4096 886 ns 886 ns 776564
133
+ STX_append/32768 7035 ns 7033 ns 86241
134
+ SDS_split_join/8 13 us 13 us 52485
135
+ SDS_split_join/64 42 us 42 us 16515
136
+ SDS_split_join/512 263 us 263 us 2647
137
+ SDS_split_join/4096 2050 us 2050 us 339
138
+ SDS_split_join/32768 17462 us 17461 us 40
139
+ STX_split_join/8 5 us 5 us 152980
140
+ STX_split_join/64 6 us 6 us 112486
141
+ STX_split_join/512 16 us 16 us 43388
142
+ STX_split_join/4096 108 us 108 us 6412
143
+ STX_split_join/32768 1707 us 1707 us 404
142
144
```
143
145
144
146
# API
@@ -158,13 +160,11 @@ STX_split_join/32768 1638 us 1638 us 422
158
160
[ stx_append_fmt] ( #stx_append_fmt )
159
161
[ stx_append_fmt_strict] ( #stx_append_fmt_strict )
160
162
161
- #### free / adjust
162
- [ stx_free] ( #stx_free )
163
- [ stx_list_free] ( #stx_list_free )
164
- [ stx_reset] ( #stx_reset )
163
+ #### adjust / reset
165
164
[ stx_resize] ( #stx_resize )
166
165
[ stx_adjust] ( #stx_adjust )
167
166
[ stx_trim] ( #stx_trim )
167
+ [ stx_reset] ( #stx_reset )
168
168
169
169
#### assess
170
170
[ stx_cap] ( #stx_cap )
@@ -173,6 +173,10 @@ STX_split_join/32768 1638 us 1638 us 422
173
173
[ stx_equal] ( #stx_equal )
174
174
[ stx_dbg] ( #stx_dbg )
175
175
176
+ #### free
177
+ [ stx_free] ( #stx_free )
178
+ [ stx_list_free] ( #stx_list_free )
179
+
176
180
177
181
Custom allocators can be defined with
178
182
```
0 commit comments