MSUTeam / MSU

Modding Standards and Utilities for Battle Brothers
21 stars 4 forks source link

feat: add utility function for benchmarking #398

Closed LordMidas closed 1 month ago

LordMidas commented 1 month ago

This is a useful function for benchmarking a single function or comparing the benchmarks of several functions. Usage:

// Let's say we have 3 functions called foo, bar, baz
// we pass them as references in an array and assign them an id that will be printed in log
::MSU.Utils.benchmark([
    ["Endy",  foo],
    ["Midas", bar],
    ["Taro", baz]
]);

This will print to log the performance of the 3 functions as well as their relative performance to the first function i.e. in this case Endy.

In case your functions need parameters you can manually call them via passing lambdas to the utility function and using local variables as the args:

::MSU.Utils.benchmark([
    ["Endy",  @() foo(pass args here)],
    ["Midas", @() bar(pass args here)],
    ["Taro", @() baz(pass args here)]
]);

Sample:

image