1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-12-23 13:48:23 +00:00
Funkin/source/funkin/util/TimerUtil.hx
2024-03-16 22:20:22 -04:00

50 lines
1.2 KiB
Haxe

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';
}
}