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 of GemBox.Presentation performance
GemBox.Presentation performance
using System;
using System.Diagnostics;
using System.Linq;
using GemBox.Presentation;

class Program
{
    static void Main(string[] args)
    {
        // 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/Presentation/help/html/Evaluation_and_Licensing.htm
        ComponentInfo.FreeLimitReached += (sender, e) => e.FreeLimitReachedAction = FreeLimitReachedAction.ContinueAsTrial;

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

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

        var 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 (var slide in presentation.Slides)
            foreach (var shape in slide.Content.Drawings.OfType<Shape>())
            {
                foreach (var 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 System
Imports System.Diagnostics
Imports System.Linq
Imports GemBox.Presentation

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/Presentation/help/html/Evaluation_and_Licensing.htm
        AddHandler ComponentInfo.FreeLimitReached, Sub(sender, e) e.FreeLimitReachedAction = FreeLimitReachedAction.ContinueAsTrial

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

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

        Dim presentation = 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 In presentation.Slides
            For Each shape In slide.Content.Drawings.OfType(Of Shape)

                For Each paragraph 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

Download examples from GitHub.