GemBox.Document is a .NET component that enables you to read, write, edit, convert, and print document files from your .NET applications using one simple API.

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.

Screenshot
Performance Screenshot

See the full code below.

using System;
using System.Diagnostics;
using GemBox.Document;

namespace PerformanceCs
{
    class Program
    {
        static void Main(string[] args)
        {
            // If using Professional version, put your serial key below.
            ComponentInfo.SetLicense("FREE-LIMITED-KEY");
            // If sample 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 sample:");
            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 PerformanceVb

    Sub Main()

        ' If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY")
        ' If sample 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 sample:")
        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

Check next sample.