package funkin.util; import funkin.util.tools.FloatTools; import haxe.Timer; class TimerUtil { /** * Store the current time. */ public static function start():Float { return Timer.stamp(); } /** * Return the elapsed time. */ static function took(start:Float, ?end:Float):Float { var endOrNow:Float = end != null ? end : Timer.stamp(); return endOrNow - start; } /** * Return the elapsed time in seconds as a string. * @param start The start time. * @param end The end time. * @param precision The number of decimal places to round to. * @return The elapsed time in seconds as a string. */ public static function seconds(start:Float, ?end:Float, ?precision = 2):String { var seconds:Float = FloatTools.round(took(start, end), precision); return '${seconds} seconds'; } /** * Return the elapsed time in milliseconds as a string. * @param start The start time. * @param end The end time. * @return The elapsed time in milliseconds as a string. */ public static function ms(start:Float, ?end:Float):String { var seconds:Float = took(start, end); return '${seconds * 1000} ms'; } }