The test
Today 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 Utilization
The fist thread CPU utilization chart can be seen below.Note that there are two threads but CPU utilization is only slightly above 50%.
Now the second CPU utilization chart:
Note that now CPU utilization is almost 100% (and always above 90%). Of course there are a few LOCKed instructions here and there, but it is clearly more multi-core friendly.
The results
Original 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.
1 comment:
Lovely post, thanks for posting
Post a Comment