Performances on large Word in C# and VB.NET

Following example 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 example.

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

Performance Screenshot
using System;
using System.Diagnostics;
using GemBox.Document;

class Program
{
    static void Main()
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");
        // If example exceeds Free version limitations then continue as trial version: 
        // https://www.gemboxsoftware.com/Document/help/html/Evaluation_and_Licensing.htm
        ComponentInfo.FreeLimitReached += (sender, e) => e.FreeLimitReachedAction = FreeLimitReachedAction.ContinueAsTrial;

        Console.WriteLine("Performance example:");
        Console.WriteLine();

        Stopwatch stopwatch = new Stopwatch();
        stopwatch.Start();

        DocumentModel document = DocumentModel.Load("Template.docx", LoadOptions.DocxDefault);

        Console.WriteLine("Load file (seconds): " + stopwatch.Elapsed.TotalSeconds);

        stopwatch.Reset();
        stopwatch.Start();

        int numberOfParagraphs = 0;
        foreach (var item in document.GetChildElements(true, ElementType.Paragraph))
            ++numberOfParagraphs;

        Console.WriteLine("Iterate through " + numberOfParagraphs + " paragraphs (seconds): " + stopwatch.Elapsed.TotalSeconds);

        stopwatch.Reset();
        stopwatch.Start();

        document.Save("Report.docx");

        Console.WriteLine("Save file (seconds): " + stopwatch.Elapsed.TotalSeconds);
    }
}
Imports System
Imports System.Diagnostics
Imports GemBox.Document

Module Program

    Sub Main()

        ' If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY")
        ' If example exceeds Free version limitations then continue as trial version: 
        ' https://www.gemboxsoftware.com/Document/help/html/Evaluation_and_Licensing.htm
        AddHandler ComponentInfo.FreeLimitReached, Sub(sender, e) e.FreeLimitReachedAction = FreeLimitReachedAction.ContinueAsTrial

        Console.WriteLine("Performance example:")
        Console.WriteLine()

        Dim stopwatch As New Stopwatch()
        stopwatch.Start()

        Dim document As DocumentModel = DocumentModel.Load("Template.docx", LoadOptions.DocxDefault)

        Console.WriteLine("Load file (seconds): " & stopwatch.Elapsed.TotalSeconds)

        stopwatch.Reset()
        stopwatch.Start()

        Dim numberOfParagraphs As Integer = 0
        For Each item As Paragraph In document.GetChildElements(True, ElementType.Paragraph)
            numberOfParagraphs += 1
        Next

        Console.WriteLine("Iterate through " & numberOfParagraphs & " paragraphs (seconds): " & stopwatch.Elapsed.TotalSeconds)

        stopwatch.Reset()
        stopwatch.Start()

        document.Save("Report.docx")

        Console.WriteLine("Save file (seconds): " & stopwatch.Elapsed.TotalSeconds)

    End Sub

End Module

Download examples from GitHub.