Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/klib/blob/master/test/kseq_bench.c # klib [Ported from github.com/attractivechaos/klib] added block arena Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `klib / test / kseq_bench.c` 69 lines ยท 1572 bytes Raw Blame History 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include "kseq.h" 7 8 #define BUF_SIZE 4096 9 KSTREAM_INIT(gzFile, gzread, BUF_SIZE) 10 11 int main(int argc, char *argv[]) 12 { 13 gzFile fp; 14 clock_t t; 15 if (argc == 1) { 16 fprintf(stderr, "Usage: kseq_bench \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 }