modified: src1/input.c
[GalaxyCodeBases.git] / c_cpp / lib / klib / test / kseq_bench.c
blobeeda13f71726467d883b1ed91e8d57e91cd1c54e
1 #include <zlib.h>
2 #include <stdio.h>
3 #include <time.h>
4 #include <stdint.h>
5 #include <stdlib.h>
6 #include "kseq.h"
8 #define BUF_SIZE 4096
9 KSTREAM_INIT(gzFile, gzread, BUF_SIZE)
11 int main(int argc, char *argv[])
13 gzFile fp;
14 clock_t t;
15 if (argc == 1) {
16 fprintf(stderr, "Usage: kseq_bench <in.gz>\n");
17 return 1;
20 uint8_t *buf = malloc(BUF_SIZE);
21 fp = gzopen(argv[1], "r");
22 t = clock();
23 while (gzread(fp, buf, BUF_SIZE) > 0);
24 fprintf(stderr, "[gzread] %.2f sec\n", (float)(clock() - t) / CLOCKS_PER_SEC);
25 gzclose(fp);
26 free(buf);
29 kstream_t *ks;
30 fp = gzopen(argv[1], "r");
31 ks = ks_init(fp);
32 t = clock();
33 while (ks_getc(ks) >= 0);
34 fprintf(stderr, "[ks_getc] %.2f sec\n", (float)(clock() - t) / CLOCKS_PER_SEC);
35 ks_destroy(ks);
36 gzclose(fp);
39 kstream_t *ks;
40 kstring_t *s;
41 int dret;
42 s = calloc(1, sizeof(kstring_t));
43 fp = gzopen(argv[1], "r");
44 ks = ks_init(fp);
45 t = clock();
46 while (ks_getuntil(ks, '\n', s, &dret) >= 0);
47 fprintf(stderr, "[ks_getuntil] %.2f sec\n", (float)(clock() - t) / CLOCKS_PER_SEC);
48 ks_destroy(ks);
49 gzclose(fp);
50 free(s->s); free(s);
52 if (argc == 2) {
53 fp = gzopen(argv[1], "r");
54 t = clock();
55 while (gzgetc(fp) >= 0);
56 fprintf(stderr, "[gzgetc] %.2f sec\n", (float)(clock() - t) / CLOCKS_PER_SEC);
57 gzclose(fp);
59 if (argc == 2) {
60 char *buf = malloc(BUF_SIZE);
61 fp = gzopen(argv[1], "r");
62 t = clock();
63 while (gzgets(fp, buf, BUF_SIZE) > 0);
64 fprintf(stderr, "[gzgets] %.2f sec\n", (float)(clock() - t) / CLOCKS_PER_SEC);
65 gzclose(fp);
66 free(buf);
68 return 0;