interplane.Get Omega
Read in your language

klib

[Ported from github.com/attractivechaos/klib] added block arena

Brought by drakestapleton

branch master Branches Tags History

klib / test / kseq_bench.c

69 lines · 1572 bytes Raw Blame History
1#include <zlib.h>
2#include <stdio.h>
3#include <time.h>
4#include <stdint.h>
5#include <stdlib.h>
6#include "kseq.h"
7
8#define BUF_SIZE 4096
9KSTREAM_INIT(gzFile, gzread, BUF_SIZE)
10
11int main(int argc, char *argv[])
12{
13 gzFile fp;
14 clock_t t;
15 if (argc == 1) {
16 fprintf(stderr, "Usage: kseq_bench <in.gz>\n");
17 return 1;
18 }
19 {
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);
27 }
28 {
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);
37 }
38 {
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);
51 }
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);
58 }
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);
67 }
68 return 0;
69}