Skip to content

Commit 75482c2

Browse files
committed
1.53
1 parent bd32115 commit 75482c2

File tree

5 files changed

+94
-3
lines changed

5 files changed

+94
-3
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package dev.felnull.fnjl;
22

33
public class FNJLBuildIn {
4-
protected static final String VERSION = "1.52";
4+
protected static final String VERSION = "1.53";
55
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package dev.felnull.fnjl.debug;
2+
3+
4+
/**
5+
* 処理時間計測
6+
*
7+
* @author MORIMORI0317
8+
*/
9+
public class ProcessTimeMeasure {
10+
private long elapsedTime;
11+
private long lastElapsedTime;
12+
private int sampleCount;
13+
private long lastPrintTime;
14+
private long lastResetTime;
15+
16+
public void process(Runnable runnable) {
17+
long st = System.nanoTime();
18+
runnable.run();
19+
lap(System.nanoTime() - st);
20+
}
21+
22+
public void lap(long elapsed) {
23+
elapsedTime += elapsed;
24+
lastElapsedTime = elapsed;
25+
sampleCount++;
26+
}
27+
28+
public void reset() {
29+
elapsedTime = 0;
30+
sampleCount = 0;
31+
lastResetTime = System.currentTimeMillis();
32+
}
33+
34+
public MeasureResult getResult() {
35+
if (elapsedTime <= 0 || sampleCount <= 0)
36+
throw new IllegalStateException("Unmeasured");
37+
return new MeasureResult(elapsedTime, sampleCount, lastElapsedTime);
38+
}
39+
40+
public void printResult(long time) {
41+
if (System.currentTimeMillis() - lastPrintTime >= time) {
42+
System.out.println(getResult());
43+
lastPrintTime = System.currentTimeMillis();
44+
}
45+
}
46+
47+
public void printResult(long time, long resetTime) {
48+
printResult(time);
49+
if (System.currentTimeMillis() - lastResetTime >= resetTime) {
50+
reset();
51+
lastResetTime = System.currentTimeMillis();
52+
}
53+
}
54+
55+
public static class MeasureResult {
56+
private final long elapsed;
57+
private final long sampleCount;
58+
private final long lastElapsedTime;
59+
60+
public MeasureResult(long elapsed, long sampleCount, long lastElapsedTime) {
61+
this.elapsed = elapsed;
62+
this.sampleCount = sampleCount;
63+
this.lastElapsedTime = lastElapsedTime;
64+
}
65+
66+
public double getAverage() {
67+
return (double) elapsed / (double) sampleCount;
68+
}
69+
70+
@Override
71+
public String toString() {
72+
double avg = getAverage();
73+
return String.format("Elapsed Time: %.3fμs %06dns, Average Time: %.3fμs %.3fns, Count %s, Last Lap: %.3fμs %06dns", elapsed / 1000000d, elapsed, avg / 1000000d, avg, sampleCount, lastElapsedTime / 1000000d, lastElapsedTime);
74+
}
75+
76+
public long getElapsed() {
77+
return elapsed;
78+
}
79+
80+
public long getSampleCount() {
81+
return sampleCount;
82+
}
83+
84+
public long getLapTime() {
85+
return lastElapsedTime;
86+
}
87+
}
88+
}

common/src/main/java/dev/felnull/fnjl/util/FNDataUtil.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,9 @@ public static byte[] fileLoadToProgress(File file, Consumer<ProgressWriter.Write
282282
* @return InputStream
283283
*/
284284
public static InputStream resourceExtractor(Class<?> targetClass, String path) {
285+
if (path.startsWith("/"))
286+
path = path.substring(1);
287+
285288
InputStream stream = targetClass.getResourceAsStream("/" + path);
286289
if (stream == null)
287290
stream = ClassLoader.getSystemResourceAsStream(path);

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
fnjl_group=dev.felnull
22
fnjl_name=felnull-java-library
3-
fnjl_version=1.52
3+
fnjl_version=1.53
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package dev.felnull.fnjln;
22

33
public class FNJLNBuildIn {
4-
protected static final String VERSION = "1.52";
4+
protected static final String VERSION = "1.53";
55

66
protected static final int NATIVE_LIBRARY_VERSION = 1;
77
}

0 commit comments

Comments
 (0)