1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-11-16 03:43:36 +00:00
Funkin/source/funkin/util/TimerUtil.hx

50 lines
1.2 KiB
Haxe
Raw Normal View History

2024-03-14 01:47:15 +00:00
package funkin.util;
import funkin.util.tools.FloatTools;
import haxe.Timer;
2024-03-14 01:47:15 +00:00
class TimerUtil
{
2024-03-17 02:20:22 +00:00
/**
* Store the current time.
*/
public static function start():Float
{
return Timer.stamp();
}
2024-03-17 02:20:22 +00:00
/**
* Return the elapsed time.
*/
static function took(start:Float, ?end:Float):Float
{
var endOrNow:Float = end != null ? end : Timer.stamp();
return endOrNow - start;
}
2024-03-17 02:20:22 +00:00
/**
* 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';
}
2024-03-17 02:20:22 +00:00
/**
* 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';
}
}