Name: Anonymous 2017-01-18 6:20
It's a good idea to learn Haskell even if you don't like it or agree with its ideals.
Conventional wisdom says that no programming language is faster than C, and all higher level languages (such as Haskell) are doomed to be much slower because of their distance from the real machine.It's very easy to make a programming language faster than C, but hard to make a garbage collected or dynamically typed language faster than C.
getBlocks = map mkBlock . drop 1 . B.split '>' <$> B.getContents
where
mkBlock bs1 = Block h t
where (h, t) = B.break (== '\n') bs1
But if you aren't planning to do a significant amount of micro-optimisation then you don't need C. Haskell will give you the same performance, or better, and cut your development and maintenance costs by 75 to 90 percent as well.
Try rewriting this in C, for example:C version is twice faster
Haskell will give you the same performance, or better
#include <stdio.h>
int read_fasta_sequence(char *hdr, int nh, char *seq, int ns, FILE *fin)
{
char ch;
if (fscanf(fin, " %c", &ch) != 1 || ch != '>' || !fgets(hdr, nh, fin))
return 0;
while (fscanf(fin, " %c", &ch) == 1 && ch != '>')
if (ns-- > 1)
*seq++ = ch;
*seq = '\0';
ungetc(ch, fin);
return (ns > 0);
}
int main(void)
{
char hdr[0x100], seq[0x10000];
while (read_fasta_sequence(hdr, sizeof hdr, seq, sizeof seq, stdin))
printf(">%s\n%s\n", hdr, seq);
}