added Util.time
This commit is contained in:
parent
7a1b5d0c73
commit
59c918299d
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue