Performance of exception handling

Andrej Mitrovic andrej.mitrovich at gmail.com
Mon May 9 20:09:02 PDT 2011


I'll have to agree that exceptions are quite slow. I was just testing
out UTF's decode() function on this UTF-8 test file:
http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt .

It has a few dozen invalid UTF sequences and is a good stress-test for
a decoder. The  std.utf.decode function throws an exception on invalid
UTF sequences.

On that test file (only 20 kilobytes large), loading of a file and
skipping invalid sequences takes 210msecs.

If I change decode() to use a bool to flag invalid sequences instead
of using exceptions, the UTF test file is parsed in 1.4msecs. Now
that's quite a difference.

Also, loading and validating a 400 kilobyte text file is done in
35msecs, which I'm quite happy about. I'm not sure if the Scintilla
editing component applies syntax coloring on the entire file before
displaying any lines, but if not then I could easily beat its
performance. It takes about a second for it to load and display a
400kbyte source file (with syntax highlighting of course).


More information about the Digitalmars-d mailing list