on master help sign in
Add lazy text variant

--HG-- extra : convert_revision : 439f9304f98a0cae561427760995f2991dc10e00

commit8b56910f02ac7235d569059f0c75b2d473d2e0e5 authorBryan O'Sullivan <bos@serpentine.com> dateTue 17 Aug 2010, 03:15 (16 years ago) parent10a0bb2
2 files changed+20−2
tests/benchmarks/Makefile+1−1 tests/benchmarks/fileread.c+19−1
tests/benchmarks/Makefile+1−1
@@ -1,5 +1,5 @@
11CC := $(shell icu-config --cc)
2−CFLAGS := $(shell icu-config --cflags)
2+CFLAGS := -g $(shell icu-config --cflags)
33CPPFLAGS := $(shell icu-config --cppflags)
44LDFLAGS := $(CFLAGS) $(shell icu-config --ldflags --ldflags-icuio)
55
tests/benchmarks/fileread.c+19−1
@@ -3,6 +3,22 @@
33#include <stdlib.h>
44#include <string.h>
55
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+
622void text(const char *name)
723{
824 UFILE *ufp = u_fopen(name, "r", NULL, "UTF-8");
@@ -29,7 +45,9 @@ int main(int argc, char **argv)
2945 exit(1);
3046 }
3147
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)
3351 text(argv[2]);
3452 else {
3553 fprintf(stderr, "no matching handler\n");