String compare performance

bearophile bearophileHUGS at lycos.com
Sun Nov 28 09:00:00 PST 2010


spir:

> Yes, but other comments seems to show memcmp only doubles speed. This would only bring us twice as slow as python ;-)

The solution I suggest for this problem is: when DMD knows at compile-time the length of one of the two strings to equate, and such length is small (like < 6), then it may replace the string eq code like this:
(codon == "TAG")
With code like:
(codon.length == 3 && codon[0] == 'T' && codon[1] == 'A' && codon[2] == 'G')

Bye,
bearophile


More information about the Digitalmars-d mailing list