On 1 April 2014 19:35, Walter Bright <newshou...@digitalmars.com> wrote: > Try this benchmark comparing various classification schemes:
GDC turns switches into table lookups, and speeds are comparable on my system, though your little hack is appears faster in release builds. Tests are with 1 million runs. --- Non-release run: Milliseconds 1797 1642 1501 1463 Non-release run, no bounds checking: Milliseconds 1730 1611 1483 1512 Release run: Milliseconds 1753 1633 1471 1528 Optimised run: Milliseconds 0 0 0 0 --- It is interesting that switches seem to take longer when bounds checking is turned off, and even longer when in release mode. However this is not very conclusive as I can't test with optimisations turned on. Unfortunately for your small program, gcc is too smart and optimises everything away. --- bool isIdentifierChar3(ubyte c) { switch(c) { case '0': .. case '9': case 'A': .. case 'Z': case 'a': .. case 'z': case '$': case '_': return true; default: return false; } }