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

The following example shows how you can 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.

GemBox.Presentation performance
Screenshot of GemBox.Presentation performance
using System;
using System.Diagnostics;
using System.Linq;
using GemBox.Presentation;

class Program
{
    static void Main()
    {
        // If using the Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        // If using Free version and example exceeds its limitations, use Trial or Time Limited version:
        // https://www.gemboxsoftware.com/presentation/examples/c-sharp-free-professional-powerpoint-library/901
        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 the Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY")

        ' If using Free version and example exceeds its limitations, use Trial or Time Limited version:
        ' https://www.gemboxsoftware.com/presentation/examples/c-sharp-free-professional-powerpoint-library/901
        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

See also


Next steps

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

Download Buy