In this post, we'll take a look at a performance comparison between the new TX Text Control Core and the traditional TX Text Control Classic. We'll examine how both versions perform under increasing workloads, specifically measuring the time it takes to load a plain text document and export it to DOCX and PDF formats.
Test Setup
We designed a simple benchmark to simulate real-world use. Every test:
- Generates a text file containing a variable number of lines (100, 500, 5,000, 50,000, and 100,000)
- Loads the content into a ServerTextControl instance
- Exports the content to either PDF or DOCX format
- Measures the elapsed time in milliseconds
Each test run was performed using both the Classic and Core libraries.
using System.Diagnostics; | |
using System.Text; | |
using TXTextControl; | |
// Define the line counts to test | |
int[] lineCounts = new int[] { 100, 100, 500, 5000, 50000, 100000 }; | |
foreach (int lineCount in lineCounts) | |
{ | |
Console.WriteLine($"--- Testing with {lineCount} lines ---"); | |
string longText = GenerateLongText(lineCount); | |
Stopwatch sw = new Stopwatch(); | |
int numPages; | |
sw.Start(); | |
using (ServerTextControl textControl = new ServerTextControl()) | |
{ | |
textControl.Create(); | |
textControl.Load(longText, StringStreamType.PlainText); | |
byte[] data; | |
textControl.Save(out data, BinaryStreamType.WordprocessingML); | |
//textControl.Save(out data, BinaryStreamType.AdobePDF); | |
numPages = textControl.Pages; | |
} | |
sw.Stop(); | |
Console.WriteLine($"Lines: {lineCount}"); | |
Console.WriteLine($"Time: {sw.ElapsedMilliseconds} ms"); | |
Console.WriteLine($"Pages: {numPages}"); | |
Console.WriteLine(); | |
} | |
static string GenerateLongText(int numberOfLines) | |
{ | |
StringBuilder sb = new StringBuilder(); | |
for (int i = 0; i < numberOfLines; i++) | |
{ | |
sb.AppendLine(Guid.NewGuid().ToString()); | |
} | |
return sb.ToString(); | |
} |
Test Results
The results of our tests are summarized in the following table:
Lines | Core (DOCX) | Core (PDF) | Classic (DOCX) | Classic (PDF) |
---|---|---|---|---|
100 | 11 ms | 23 ms | 51 ms | 214 ms |
500 | 19 ms | 76 ms | 72 ms | 839 ms |
5,000 | 113 ms | 684 ms | 289 ms | 7,842 ms |
50,000 | 1,271 ms | 6,957 ms | 2,697 ms | 78,921 ms |
100,000 | 3,047 ms | 14,518 ms | 5,885 ms | 159,313 ms |
To give you an idea of document size, 100,000 lines of text results in a 1588-page document. The following visualizations will show you the differences in a much more obvious way.
TX Text Control Core significantly outperforms the Classic version when exporting to DOCX. Core is consistently 2 to 5 times faster than Classic. The performance gap increases with document size, an indication of better scalability in the core.
When exporting to PDF, the performance difference is even more pronounced. Core is up to 11 times faster than Classic, depending on the document size. Core scales linearly, while Classic incurs growing overhead at larger sizes.
Linear Scaling
Performance is very close to linear, with a slightly steeper curve as the document grows. TX Text Control Core is designed for high performance and scalability. The results show that the Core library scales almost linearly with document size, while the performance of the Classic library degrades significantly with larger documents.
In conclusion, if you are looking for a library that can handle large documents efficiently, TX Text Control Core is the clear choice. It outperforms the Classic version in both DOCX and PDF exports, making it the better option for modern applications.