The testToday I created a new multi-threaded test. Two threads running in parallel doing the same thing: Taking a string and using TextToHTMLStringLiteral to convert it multiple times, inside a tight loop. During the first test, both threads used the original TextToHTMLStringLiteral implementation. In the second test, I used my modified version. Both threads execute the following code:
procedure TMyThread.Execute; begin FCount := 0; repeat FStr := 'ABCD XPTO %^&* ABCD XPTO %^&* ABCD XPTO %^&*'; FStr := TextToHTMLStringLiteral(FStr); Inc(FCount); until FCount = MaxCount; end;
CPU UtilizationThe fist thread CPU utilization chart can be seen below.
Now the second CPU utilization chart:
The resultsOriginal TextToHTMLStringLiteral time: 24.4 seconds (using ~ 55% CPU x 2)
Modified TextToHTMLStringLiteral time: 3.6 seconds (using ~ 98% CPU x 2) The time measures showed that the modified code performs almost 7 times better than the original, using 2 threads (It was 6 times better in a single thread app). We can expect that the more cores you have, the bigger will be time difference.