Verse Library verse

01 Device

Measures execution time of a task loop and prints results to check if performance meets timing thresholds.

verse-library/performance-based-rows/01-device.verse

# This is our main script. It runs when the game starts.
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /Verse.org/Native }

# We define our device class.
performance_checker_device := class(creative_device):

    # We define a function called MeasurePerformance.
    # A function is a list of steps we can reuse.
    MeasurePerformance()<suspends>: void =
        # Start a stopwatch.
        # This is like saying "Go!" at the start of a race.
        StartTime : float = GetSimulationElapsedTime()

        # Do a small task.
        # Let's pretend this is a complex game calculation.
        # We will just count up many times.
        var Accumulator : int = 0
        loop:
            # This loop runs 1000 times.
            # It takes a little time to finish.
            set Accumulator += 1
            if (Accumulator >= 1000):
                break

        # Stop the stopwatch.
        # This is like saying "Stop!" at the end of the race.
        EndTime : float = GetSimulationElapsedTime()

Sign in free to read the full source 🌴

This Verse Library file is members-only. Create a free account to view the complete source and download the .verse file.

Sign in with Discord

Comments

    Sign in to vote, comment, or suggest an edit. Sign in