local ____lualib = require("lualib_bundle")
local __TS__ArrayEntries = ____lualib.__TS__ArrayEntries
local __TS__Iterator = ____lualib.__TS__Iterator
local ____exports = {}
local ____log = require("functions.log")
local log = ____log.log
--- Helper function to benchmark the performance of a function.
-- 
-- This function is variadic, which means that you can supply as many functions as you want to
-- benchmark.
-- 
-- This function uses the `Isaac.GetTime` method to record how long the function took to execute.
-- This method only reports time in milliseconds. For this reason, if you are benchmarking smaller
-- functions, then you should provide a very high value for the number of trials.
-- 
-- @returns An array containing the average time in milliseconds for each function. (This will also
-- be printed to the log.)
function ____exports.benchmark(self, numTrials, ...)
    local functions = {...}
    log(((("Benchmarking " .. tostring(#functions)) .. " function(s) with ") .. tostring(numTrials)) .. " trials.")
    local averages = {}
    for ____, ____value in __TS__Iterator(__TS__ArrayEntries(functions)) do
        local i = ____value[1]
        local func = ____value[2]
        local totalTimeMilliseconds = 0
        do
            local j = 0
            while j < numTrials do
                local startTimeMilliseconds = Isaac.GetTime()
                func(nil)
                local endTimeMilliseconds = Isaac.GetTime()
                local elapsedTimeMilliseconds = endTimeMilliseconds - startTimeMilliseconds
                totalTimeMilliseconds = totalTimeMilliseconds + elapsedTimeMilliseconds
                j = j + 1
            end
        end
        local averageTimeMilliseconds = totalTimeMilliseconds / numTrials
        log(((("The average time of the function at index " .. tostring(i)) .. " is: ") .. tostring(averageTimeMilliseconds)) .. " milliseconds")
        averages[#averages + 1] = averageTimeMilliseconds
    end
    return averages
end
return ____exports
