on master help sign in
Add C fileread benchmark

--HG-- extra : convert_revision : b322fb33f42089d7bdf79f705e79a2162ea104f5

commit10a0bb23badb9520c4211694fe7e4062d7c74d9f authorBryan O'Sullivan <bos@serpentine.com> dateTue 17 Aug 2010, 03:08 (16 years ago) parent31ac4c0
2 files changed+53
tests/benchmarks/Makefile+13 tests/benchmarks/fileread.c+40
tests/benchmarks/Makefilenew file+13
@@ -0,0 +1,13 @@
1+CC := $(shell icu-config --cc)
2+CFLAGS := $(shell icu-config --cflags)
3+CPPFLAGS := $(shell icu-config --cppflags)
4+LDFLAGS := $(CFLAGS) $(shell icu-config --ldflags --ldflags-icuio)
5+
6+all := fileread
7+
8+all: $(all)
9+
10+fileread: fileread.o
11+
12+clean:
13+ -rm -f *.hi *.o $(all)
tests/benchmarks/fileread.cnew file+40
@@ -0,0 +1,40 @@
1+#include <unicode/ustdio.h>
2+#include <stdio.h>
3+#include <stdlib.h>
4+#include <string.h>
5+
6+void text(const char *name)
7+{
8+ UFILE *ufp = u_fopen(name, "r", NULL, "UTF-8");
9+ FILE *fp = u_fgetfile(ufp);
10+ UChar *str;
11+ long fsize;
12+ int32_t n;
13+
14+ fseek(fp, 0, SEEK_END);
15+ fsize = ftell(fp);
16+ u_frewind(ufp);
17+
18+ str = malloc(sizeof(*str) * fsize);
19+
20+ n = u_file_read(str, fsize, ufp);
21+
22+ printf("%d\n", n);
23+}
24+
25+int main(int argc, char **argv)
26+{
27+ if (argc != 3) {
28+ fprintf(stderr, "Usage: fileread handler filename\n");
29+ exit(1);
30+ }
31+
32+ if (strcmp(argv[1], "text") == 0)
33+ text(argv[2]);
34+ else {
35+ fprintf(stderr, "no matching handler\n");
36+ return 1;
37+ }
38+
39+ return 0;
40+}