Performances on large Word in C# and VB.NET

Following sample demonstrates how to test performance of GemBox.Document component on large document files when using the Free version of the component.

If free version limits are exceeded, component will continue to work in Trial mode if FreeLimitReached event is handled as in the sample.

For more information about Trial mode limitations, see GemBox.Document Evaluation and Licensing help page.

Screenshot

Performance Screenshot

See the full code below.

1using System;
2using System.Diagnostics;
3using GemBox.Document;
4
5namespace PerformanceCs
6{
7    class Program
8    {
9        static void Main(string[] args)
10        {
11            // If using Professional version, put your serial key below.
12            ComponentInfo.SetLicense("FREE-LIMITED-KEY");
13            // If sample exceeds Free version limitations then continue as trial version: 
14            // http://www.gemboxsoftware.com/Document/help/html/Evaluation_and_Licensing.htm
15            ComponentInfo.FreeLimitReached += (sender, e) => e.FreeLimitReachedAction = FreeLimitReachedAction.ContinueAsTrial;
16
17            Console.WriteLine("Performance sample:");
18            Console.WriteLine();
19
20            Stopwatch stopwatch = new Stopwatch();
21            stopwatch.Start();
22
23            DocumentModel document = DocumentModel.Load("Template.docx", LoadOptions.DocxDefault);
24
25            Console.WriteLine("Load file (seconds): " + stopwatch.Elapsed.TotalSeconds);
26
27            stopwatch.Reset();
28            stopwatch.Start();
29
30            int numberOfParagraphs = 0;
31            foreach (var item in document.GetChildElements(true, ElementType.Paragraph))
32                ++numberOfParagraphs;
33
34            Console.WriteLine("Iterate through " + numberOfParagraphs + " paragraphs (seconds): " + stopwatch.Elapsed.TotalSeconds);
35
36            stopwatch.Reset();
37            stopwatch.Start();
38
39            document.Save("Report.docx");
40
41            Console.WriteLine("Save file (seconds): " + stopwatch.Elapsed.TotalSeconds);
42        }
43    }
44}
1Imports System
2Imports System.Diagnostics
3Imports GemBox.Document
4
5Module PerformanceVb
6
7    Sub Main()
8
9        ' If using Professional version, put your serial key below.
10        ComponentInfo.SetLicense("FREE-LIMITED-KEY")
11        ' If sample exceeds Free version limitations then continue as trial version: 
12        ' http://www.gemboxsoftware.com/Document/help/html/Evaluation_and_Licensing.htm
13        AddHandler ComponentInfo.FreeLimitReached, Sub(sender, e) e.FreeLimitReachedAction = FreeLimitReachedAction.ContinueAsTrial
14
15        Console.WriteLine("Performance sample:")
16        Console.WriteLine()
17
18        Dim stopwatch As New Stopwatch()
19        stopwatch.Start()
20
21        Dim document As DocumentModel = DocumentModel.Load("Template.docx", LoadOptions.DocxDefault)
22
23        Console.WriteLine("Load file (seconds): " & stopwatch.Elapsed.TotalSeconds)
24
25        stopwatch.Reset()
26        stopwatch.Start()
27
28        Dim numberOfParagraphs As Integer = 0
29        For Each item As Paragraph In document.GetChildElements(True, ElementType.Paragraph)
30            numberOfParagraphs += 1
31        Next
32
33        Console.WriteLine("Iterate through " & numberOfParagraphs & " paragraphs (seconds): " & stopwatch.Elapsed.TotalSeconds)
34
35        stopwatch.Reset()
36        stopwatch.Start()
37
38        document.Save("Report.docx")
39
40        Console.WriteLine("Save file (seconds): " & stopwatch.Elapsed.TotalSeconds)
41
42    End Sub
43
44End Module

Check next sample or find out more about GemBox.Document and GemBox Software.