From 59c918299da7f8eb75b9aaf73889c1148bf2f0a5 Mon Sep 17 00:00:00 2001 From: DaniTheSkunk <> Date: Sun, 27 Nov 2022 06:59:39 +0000 Subject: [PATCH] added Util.time --- com/danitheskunk/skunkworks/Util.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/com/danitheskunk/skunkworks/Util.java b/com/danitheskunk/skunkworks/Util.java index 46c27a9..4f03b8b 100644 --- a/com/danitheskunk/skunkworks/Util.java +++ b/com/danitheskunk/skunkworks/Util.java @@ -1,5 +1,7 @@ package com.danitheskunk.skunkworks; +import org.lwjgl.glfw.GLFW; + public class Util { public static String nullTerminatedCharArrayToString(char[] chars) { int len = chars.length; @@ -19,4 +21,17 @@ public class Util { public static int tweenInt(int a, int b, double amount) { return (int) ((b - a) * amount + a); } + + public static void time(Runnable run) { + time(run, 1); + } + + public static void time(Runnable run, int times) { + double now = GLFW.glfwGetTime(); + for(int i = 0; i < times; ++i) { + run.run(); + } + double end = GLFW.glfwGetTime(); + System.out.printf("%f seconds per iteration.\n", (end-now)/times); + } }