on master help sign in
Add lazy text variant
8b56910Bryan O'Sullivan
tests/benchmarks/Makefile+1−1
@@ -1,5 +1,5 @@
1CC := $(shell icu-config --cc)
1CC := $(shell icu-config --cc)
2−CFLAGS := $(shell icu-config --cflags)
2+CFLAGS := -g $(shell icu-config --cflags)
3CPPFLAGS := $(shell icu-config --cppflags)
3CPPFLAGS := $(shell icu-config --cppflags)
4LDFLAGS := $(CFLAGS) $(shell icu-config --ldflags --ldflags-icuio)
4LDFLAGS := $(CFLAGS) $(shell icu-config --ldflags --ldflags-icuio)
5
5
tests/benchmarks/fileread.c+19−1
@@ -3,6 +3,22 @@
3#include <stdlib.h>
3#include <stdlib.h>
4#include <string.h>
4#include <string.h>
5
5
6+void lazytext(const char *name)
7+{
8+ UFILE *ufp = u_fopen(name, "r", NULL, "UTF-8");
9+ const size_t bufsize = sizeof(UChar) * 32 * 1024;
10+ UChar *str = malloc(bufsize);
11+ long len = 0;
12+ int32_t n;
13+
14+ do {
15+ n = u_file_read(str, bufsize, ufp);
16+ len += n;
17+ } while (n > 0);
18+
19+ printf("%ld\n", len);
20+}
21+
6void text(const char *name)
22void text(const char *name)
7{
23{
8 UFILE *ufp = u_fopen(name, "r", NULL, "UTF-8");
24 UFILE *ufp = u_fopen(name, "r", NULL, "UTF-8");
@@ -29,7 +45,9 @@ int main(int argc, char **argv)
29 exit(1);
45 exit(1);
30 }
46 }
31
47
32− if (strcmp(argv[1], "text") == 0)
48+ if (strcmp(argv[1], "lazytext") == 0)
49+ lazytext(argv[2]);
50+ else if (strcmp(argv[1], "text") == 0)
33 text(argv[2]);
51 text(argv[2]);
34 else {
52 else {
35 fprintf(stderr, "no matching handler\n");
53 fprintf(stderr, "no matching handler\n");