title: Increase speed of reading gz file in C
body: <p>I have written a small <code>C</code> program. It does read some gzipped files, does some filtering and then again outputs to gzipped files.</p>
  <p>I run gcc with <code>-O3 -Ofast</code>. Otherwise pretty standard.</p>
  <p>If I do <code>strace -c</code> on my executable I get:</p>
  <pre><code>% time     seconds  usecs/call     calls    errors syscall
  ------ ----------- ----------- --------- --------- ----------------
   46.01    0.077081           0    400582           read
   42.73    0.071579        4771        15           munmap
    9.34    0.015647           0    110415           brk
    1.01    0.001688          32        52           openat
    0.45    0.000746           3       228           mmap
    0.20    0.000327           4        70           mprotect
    0.15    0.000254           0      1128           write
    0.06    0.000100           2        50           fstat
    0.05    0.000087           1        52           close
    0.00    0.000006           6         1           getrandom
    0.00    0.000005           2         2           rt_sigaction
    0.00    0.000004           2         2         1 arch_prctl
    0.00    0.000003           3         1         1 stat
    0.00    0.000003           1         2           lseek
    0.00    0.000002           2         1           rt_sigprocmask
    0.00    0.000002           2         1           prlimit64
    0.00    0.000000           0         8           pread64
    0.00    0.000000           0         1         1 access
    0.00    0.000000           0         1           execve
    0.00    0.000000           0         2           fdatasync
    0.00    0.000000           0         1           set_tid_address
    0.00    0.000000           0         1           set_robust_list
  ------ ----------- ----------- --------- --------- ----------------
  100.00    0.167534                512616         3 total
  </code></pre>
  <p>So my program is quite busy with reading the file. Now, I am not sure if I can get it faster. The relevant code is the following:</p>
  <pre><code>  while (gzgets(file_pointer, line, LL) != Z_NULL) {
         linkage = strtok(line,&quot;\t&quot;);
         linkage = strtok(NULL,&quot;\t&quot;);
         linkage[strcspn(linkage, &quot;\n&quot;)] = 0;
  
         add_linkage_entry(id_cnt, linkage);
  
         id_cnt++;
      }
  </code></pre>
  <p>Do you see see room for improvement here? Is it possible to intervene manually with <code>gzread</code> or is <code>gzgets</code> doint a good job here to not read char by char?</p>
  <p>Any other advice? (Are the errors in the <code>strace</code> worrisome?)</p>
  <p>EDIT:
  <code>add_linkage_entry</code> does add an entry to a <code>uthash</code> hash table (<a href="https://troydhanson.github.io/uthash/" rel="nofollow noreferrer">https://troydhanson.github.io/uthash/</a>)</p>