Skip to content

Commit 3ac307a

Browse files
committed
wording, order
1 parent a90ea27 commit 3ac307a

File tree

3 files changed

+56
-46
lines changed

3 files changed

+56
-46
lines changed

README.md

+45-41
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ without forcing a structured type on the user.
1717
typedef const char* stx_t;
1818
```
1919

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 :
2222

2323
![schema](assets/schema.png)
2424

25-
Header and string occupy a **continuous** block of memory,
25+
Header and string occupy a **continuous** memory block,
2626
avoiding the further indirection of `{len,*str}` schemes.
2727
This technique is notably used in [SDS](https://github.com/antirez/sds),
2828
now part of [Redis](https://github.com/redis/redis).
@@ -35,16 +35,16 @@ now part of [Redis](https://github.com/redis/redis).
3535
#include "stx.h"
3636

3737
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!");
4040
printf(s);
4141
return 0;
4242
}
4343
```
4444

4545
```
4646
$ gcc app.c stx -o app && ./app
47-
Stricks or treats!
47+
Treats or...Stricks!
4848
```
4949

5050
#### Sample
@@ -102,43 +102,45 @@ split and join
102102
```
103103

104104
C++ benchmark :
105-
(depends on *libbenchmark-dev*)
105+
(depends on *libbenchmark-dev*)
106106
`make && make benchcpp`
107107

108+
On Thinkpad T420 with `cpupower frequency-set --governor performance` :
109+
108110
```
109111
------------------------------------------------------------
110112
Benchmark Time CPU Iterations
111113
------------------------------------------------------------
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
142144
```
143145

144146
# API
@@ -158,13 +160,11 @@ STX_split_join/32768 1638 us 1638 us 422
158160
[stx_append_fmt](#stx_append_fmt)
159161
[stx_append_fmt_strict](#stx_append_fmt_strict)
160162

161-
#### free / adjust
162-
[stx_free](#stx_free)
163-
[stx_list_free](#stx_list_free)
164-
[stx_reset](#stx_reset)
163+
#### adjust / reset
165164
[stx_resize](#stx_resize)
166165
[stx_adjust](#stx_adjust)
167166
[stx_trim](#stx_trim)
167+
[stx_reset](#stx_reset)
168168

169169
#### assess
170170
[stx_cap](#stx_cap)
@@ -173,6 +173,10 @@ STX_split_join/32768 1638 us 1638 us 422
173173
[stx_equal](#stx_equal)
174174
[stx_dbg](#stx_dbg)
175175

176+
#### free
177+
[stx_free](#stx_free)
178+
[stx_list_free](#stx_list_free)
179+
176180

177181
Custom allocators can be defined with
178182
```

bench/bench.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,14 @@ void u_join (const char* word, const char* sep, uint n)
213213
free((void*)pat);
214214
}
215215

216+
#define SEP "|"
217+
216218
void split_join()
217219
{
218220
SECTION("split and join")
219-
u_join (W8, "|", 5000000);
220-
u_join (W256, "|", 500000);
221+
u_join (W8, SEP, 5000000);
222+
u_join (W256, SEP, 500000);
223+
u_join (W4096, SEP, 50000);
221224
}
222225

223226

src/stx.h

+6-3
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,18 @@ long long stx_append_strict (stx_t dst, const void* src, size_t srclen);
7373
size_t stx_append_fmt (stx_t* dst, const char* fmt, ...);
7474
long long stx_append_fmt_strict (stx_t dst, const char* fmt, ...);
7575

76-
// Adjust/dispose
76+
// Adjust / reset
7777

78-
void stx_free (stx_t s);
79-
void stx_list_free (const stx_t* list);
8078
int stx_resize (stx_t *pstx, size_t newcap);
8179
void stx_reset (stx_t s);
8280
void stx_adjust (stx_t s);
8381
void stx_trim (stx_t s);
8482

83+
// Free
84+
85+
void stx_free (stx_t s);
86+
void stx_list_free (const stx_t* list);
87+
8588
// Assess
8689

8790
size_t stx_cap (stx_t s); // capacity accessor

0 commit comments

Comments
 (0)