Performance Testing with Large PowerPoint Files in C# and VB.NET

The following example demonstrates how to test the performance of the GemBox.Presentation component with large presentation files using the Free version of the component.

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

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

Screenshot
Performance Screenshot

See the full code below.

using System;
using System.Diagnostics;
using System.Linq;
using GemBox.Presentation;

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/Presentation/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();

            PresentationDocument presentation = PresentationDocument.Load("Template.pptx", LoadOptions.Pptx);

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

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

            int numberOfShapes = 0;
            int numberOfParagraphs = 0;

            foreach (Slide slide in presentation.Slides)
                foreach (Shape shape in slide.Content.Drawings.OfType<Shape>())
                {
                    foreach (TextParagraph paragraph in shape.Text.Paragraphs)
                        ++numberOfParagraphs;

                    ++numberOfShapes;
                }

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

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

            presentation.Save("Report.pptx");

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

Module Module1

    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/Presentation/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 presentation As PresentationDocument = PresentationDocument.Load("Template.pptx", LoadOptions.Pptx)

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

        stopwatch.Reset()
        stopwatch.Start()

        Dim numberOfShapes As Integer = 0
        Dim numberOfParagraphs As Integer = 0

        For Each slide As Slide In presentation.Slides
            For Each shape As Shape In slide.Content.Drawings.OfType(Of Shape)

                For Each paragraph As TextParagraph In shape.Text.Paragraphs
                    numberOfParagraphs += 1
                Next

                numberOfShapes += 1
            Next
        Next

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

        stopwatch.Reset()
        stopwatch.Start()

        presentation.Save("Report.pptx")

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

    End Sub

End Module