isaacscript-common 1.2.231 → 1.2.232

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,9 @@
2
2
  /**
3
3
  * Helper function to benchmark the performance of a function.
4
4
  *
5
- * - If one function is supplied, it will simply report the average run time of the function.
6
- * - If two functions are supplied, it will compare the average run times of the functions.
5
+ * This function is variadic, which means that you can supply as many as you want to benchmark.
6
+ *
7
+ * @returns An array containing the average time in milliseconds for each function. (This will also
8
+ * be printed to the log.)
7
9
  */
8
- export declare function benchmark(numTrials: int, function1: () => void, function2?: () => void): int[];
10
+ export declare function benchmark(numTrials: int, ...functions: Array<() => void>): int[];
@@ -1,26 +1,22 @@
1
1
  local ____lualib = require("lualib_bundle")
2
2
  local __TS__ArrayPush = ____lualib.__TS__ArrayPush
3
+ local __TS__ArrayForEach = ____lualib.__TS__ArrayForEach
3
4
  local ____exports = {}
4
5
  local ____log = require("functions.log")
5
6
  local log = ____log.log
6
- function ____exports.benchmark(self, numTrials, function1, function2)
7
- local numFunctions = function2 == nil and 1 or 2
8
- local functionsText = numFunctions == 1 and "1 function" or "2 functions"
9
- log(((("Benchmarking " .. functionsText) .. " with ") .. tostring(numTrials)) .. " trials.")
7
+ function ____exports.benchmark(self, numTrials, ...)
8
+ local functions = {...}
9
+ log(((("Benchmarking " .. tostring(#functions)) .. " function(s) with ") .. tostring(numTrials)) .. " trials.")
10
10
  local averages = {}
11
- do
12
- local i = 1
13
- while i <= numFunctions do
14
- local functionToUse = i == 1 and function1 or function2
15
- if functionToUse == nil then
16
- error("Failed to find the benchmarking function to use.")
17
- end
11
+ __TS__ArrayForEach(
12
+ functions,
13
+ function(____, func, i)
18
14
  local totalTimeMilliseconds = 0
19
15
  do
20
16
  local j = 0
21
17
  while j < numTrials do
22
18
  local startTimeMilliseconds = Isaac.GetTime()
23
- functionToUse(nil)
19
+ func(nil)
24
20
  local endTimeMilliseconds = Isaac.GetTime()
25
21
  local elapsedTimeMilliseconds = endTimeMilliseconds - startTimeMilliseconds
26
22
  totalTimeMilliseconds = totalTimeMilliseconds + elapsedTimeMilliseconds
@@ -30,9 +26,8 @@ function ____exports.benchmark(self, numTrials, function1, function2)
30
26
  local averageTimeMilliseconds = totalTimeMilliseconds / numTrials
31
27
  log(((("The average time of function " .. tostring(i)) .. " is: ") .. tostring(averageTimeMilliseconds)) .. " milliseconds")
32
28
  __TS__ArrayPush(averages, averageTimeMilliseconds)
33
- i = i + 1
34
29
  end
35
- end
30
+ )
36
31
  return averages
37
32
  end
38
33
  return ____exports
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "1.2.231",
3
+ "version": "1.2.232",
4
4
  "description": "Helper functions for IsaacScript mods",
5
5
  "keywords": [
6
6
  "isaac",