Skip to content

Commit

Permalink
add benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
dwpeng committed Mar 6, 2024
1 parent bd290d8 commit ed09a9e
Show file tree
Hide file tree
Showing 6 changed files with 464 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ test-kseq
*.so
/test-seqio-*
test-cigar
/seqkit-ben*
/benchmark-*
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,22 @@ export seqioObj := $(seqioSource:.c=.o)
export cigarSource := $(ROOT_DIR)/cigar.c
export cigarObj := $(cigarSource:.c=.o)

all: build-test libseqio.so
all: build-test libseqio.so build-benchmark

^.o:^.c
$(cc) $(CFLAGS) $(LIBS) -c $<

build-test:
$(MAKE) -C ./test

build-benchmark:
$(MAKE) -C ./benchmark

libseqio.so:
$(cc) $(CFLAGS) -fPIC -c -o seqio.o seqio.c
$(cc) -shared -fPIC -o libseqio.so seqio.o

clean:
rm -f *.o test-seqio test-kseq libseqio.so test-seqio-* test-cigar
rm -f *.o test-seqio test-kseq libseqio.so test-seqio-* test-cigar benchmark-*

.PHONY:clean
9 changes: 9 additions & 0 deletions benchmark/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
all: $(ROOT_DIR)/benchmark-seqio $(ROOT_DIR)/benchmark-kseq

$(ROOT_DIR)/benchmark-seqio: seqio.c $(seqioObj)
@$(cc) $(CFLAGS) -DREAD -o $(ROOT_DIR)/benchmark-seqio-read $^ $(LIBS)
@$(cc) $(CFLAGS) -DWRITE -o $(ROOT_DIR)/benchmark-seqio-write $^ $(LIBS)
@$(cc) $(CFLAGS) -DWRITE_GZ -o $(ROOT_DIR)/benchmark-seqio-write-gz $^ $(LIBS)

$(ROOT_DIR)/benchmark-kseq: kseq.c kseq.h $(seqioObj)
@$(cc) $(CFLAGS) -o $@ $^ $(LIBS)
53 changes: 53 additions & 0 deletions benchmark/kseq.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include "kseq.h"
#include <stdio.h>
#include <time.h>
#include <zlib.h>

KSEQ_INIT(gzFile, gzread)

inline static float
timer(void)
{
struct timespec ts;
if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1) {
return -1;
}
return (float)ts.tv_sec + (float)ts.tv_nsec / 1000000000.0;
}

static inline void
benchmark_kseq_read(char* filename)
{
gzFile fp;
kseq_t* seq;
int l;
int nseq = 0;
size_t sum_length = 0;
if (filename == NULL) {
return;
}
fp = gzopen(filename, "r");
seq = kseq_init(fp);
while ((l = kseq_read(seq)) >= 0) {
sum_length += seq->seq.l;
nseq++;
}
kseq_destroy(seq);
gzclose(fp);
printf("Sum of sequence length: %lu\n", sum_length);
printf("Number of sequences: %d\n", nseq);
}

int
main(int argc, char* argv[])
{
if (argc < 2) {
fprintf(stderr, "Usage: %s <in.seq>\n", argv[0]);
return 1;
}
float start = timer();
benchmark_kseq_read(argv[1]);
float end = timer();
printf("Time: %f\n", end - start);
return 0;
}
Loading

0 comments on commit ed09a9e

Please sign in to comment.