Let's stop parser Hell

Roman D. Boiko rb at d-coding.com
Thu Jul 5 13:16:40 PDT 2012

> isKeyword_Dummy (baseline): 2738 [microsec] total, 50 [ns / 
> lookup].
This one calculates a sum of all identifier code units. Included 
for comparison.

> isKeyword_Dictionary: 4247 [microsec] total, 242 [ns / lookup].
Check whether an identifier is a keyword using AA (dictionary) 

> isKeyword_SwitchByLengthThenByChar: 1593 [microsec] total, 91 
> [ns / lookup].
Switch by identifier length at the top, then recursively switch 
by each character. Clearly a winner, but I think it can be 
improved further.

> isKeyword_BinaryArrayLookup: 14351 [microsec] total, 820 [ns / 
> lookup].
Binary search in an ordered array of keywords.

> isKeyword_LinearArrayLookup: 59564 [microsec] total, 3405 [ns / 
> lookup].
Ditto, search is linear.

> isKeyword_UnicodeTrie: 4167 [microsec] total, 238 [ns / lookup].
Lookup a keyword in a trie, created by Dmitry. This will be 

> isKeyword_UnicodeTrieBoolLookup: 3466 [microsec] total, 198 [ns 
> / lookup].
The same, but only determines whether an identifier is a keyword, 
not which exactly.

> Total: 104183 identifiers + 17488 keywords.
Analyzed the largest Phobos file (DateTime? I didn't check the 
name.) Results are consistent for other files, too.

More information about the Digitalmars-d mailing list