On Friday, 19 May 2017 at 12:55:05 UTC, Biotronic wrote:
revComp6 seems to be the fastest, but it's probably also the least readable (a common trade-off).
Try revComp7 with -release :)

string revComp7(string bps)
{
    char[] result = new char[bps.length];
    auto p1 = result.ptr;
    auto p2 = &bps[$ - 1];
    enum AT = 'A'^'T';
    enum CG = 'C'^'G';

    while (p2 > bps.ptr)
    {
       *p1 = *p2 ^ ((*p2 == 'A' || *p2 == 'T') ? AT : CG);
        p1++;
        p2--;
    }
    return result.assumeUnique;
}

In fact, when the size of the sequence is growing time difference between procedures is shrinking, so it's much more important to use memory-efficient presentation than to optimize logic.

Reply via email to