String reverse tests

This post will be a short one. Just giving a general recommendation for people doing String processing in Delphi – use PChar or ^Char for that.

I have made a simple test program that reverses a very big string with 4 different methods. Here’s the output of the tests:

Testing String method ... 5937ms.
Testing PChar method ... 2453ms.
Testing ^Char (standard) method ... 2202ms.
Testing ^Char (2009) method ... 3203ms.

I won’t detail the implementations of the functions here – but know that probably the tests are not 100% perfect so there might be some variations, but the main point is clear — use ^Char or PChar methods when you are doing some string manipulations. The amount of code the compiler emits for direct string manipulation is just absurd (but necessary).

Test program: