r/ProgrammingLanguages • • Apr 12 '26

Discussion Made a tokenizer

I wrote the tokenizer for my language and it parses 372000Tokens per second.

My specs are i7 6700k 16gb ram.

I wonder rather my tokenizer is slow or fast and I can't find any other benchmarks to compare against.

Update:

I changed some stuff about the code and it's now performing properly. I parse a 1.3M loc test file in 0.9s And for comparison to before it's producing 5M tokens

I replaced the buffered reader with mmap. And the keywords lookup now uses a 2d hashmap grouping the keywords by length instead of having 1 hashmap and checking prefixes.

The project can be found on github: Chorus

16 Upvotes

30 comments sorted by

View all comments

Show parent comment

6

u/Big-Rub9545 Apr 12 '26

Unless the tokenizer is unusually slow (should definitely look into it if it is), the time it takes will be dwarfed by parsing or compiling, which itself will often be dwarfed by execution time.

When I benchmarked my interpreter with some more intense scripts, compilation function calls don’t even show up since most of the work happens in execution (and that’s using bytecode, which tends to make execution much faster).

So the tokenizer is certainly worth optimizing, but I wouldn’t obsess over it if it isn’t an actual problem. You’d get more gains out of optimizing your runtime.

-1

u/frenris Apr 12 '26

Good tokenization I understand is usually more expensive than parsing. Both parsing and tokenization are linear with respect to their input, but tokenizers have way more input to deal with