I wrote a bioinformatics package in golang,
in which I used a function to check whether a letter(
byte) is a valid DNA/RNA/Protein letter.
The easy way is storing the letters of alphabet in a map and check the existance of a letter.
However, when I used
go tool pprof to profile the performance,
I found the hash functions (
map cost much time (see figure below).
Then I found a faster way: storing letters in a slice,
in detail, saving a letter(
byte) at position
int(letter) of slice.
To check a letter, just chech the value of
slice[int(letter)], non-zero means
[update at 2016-06-02] Two
switch versions were also tested.
They were faster than
map version, but still slower than
Besides, it was affected by the number of
case sentences in
i.e. the bigger the alphabet size is, the slower it runs.
See the benchmark result:
source code: checkLetter_test.go