mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2025-01-03 05:44:10 -08:00
C backend: increase resolution of timer in gtk benchmark
This commit is contained in:
parent
bb3a2a22fe
commit
c58e19405c
|
@ -24,6 +24,8 @@ import org.jbox2d.dynamics.Body;
|
||||||
import org.jbox2d.dynamics.Fixture;
|
import org.jbox2d.dynamics.Fixture;
|
||||||
import org.teavm.interop.Address;
|
import org.teavm.interop.Address;
|
||||||
import org.teavm.interop.Function;
|
import org.teavm.interop.Function;
|
||||||
|
import org.teavm.interop.Import;
|
||||||
|
import org.teavm.interop.c.Include;
|
||||||
import org.teavm.samples.benchmark.shared.Scene;
|
import org.teavm.samples.benchmark.shared.Scene;
|
||||||
import org.teavm.samples.benchmark.teavm.gtk.Cairo;
|
import org.teavm.samples.benchmark.teavm.gtk.Cairo;
|
||||||
import org.teavm.samples.benchmark.teavm.gtk.GLib;
|
import org.teavm.samples.benchmark.teavm.gtk.GLib;
|
||||||
|
@ -114,17 +116,21 @@ public final class Gtk3BenchmarkStarter {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int tick() {
|
private static int tick() {
|
||||||
long start = System.currentTimeMillis();
|
long start = currentTimeNano();
|
||||||
scene.calculate();
|
scene.calculate();
|
||||||
long end = System.currentTimeMillis();
|
long end = currentTimeNano();
|
||||||
int second = (int) ((System.currentTimeMillis() - startMillisecond) / 1000);
|
int second = (int) ((System.currentTimeMillis() - startMillisecond) / 1000);
|
||||||
|
|
||||||
if (second > currentSecond) {
|
if (second > currentSecond) {
|
||||||
System.out.println("Second " + second + ": " + timeSpentCalculating + " ms");
|
System.out.println("Second " + second + ": " + (timeSpentCalculating / 1_000_000.0) + " ms");
|
||||||
timeSpentCalculating = 0;
|
timeSpentCalculating = 0;
|
||||||
currentSecond = second;
|
currentSecond = second;
|
||||||
}
|
}
|
||||||
timeSpentCalculating += end - start;
|
long delta = end - start;
|
||||||
|
if (delta < 0) {
|
||||||
|
delta += 1_000_000_000;
|
||||||
|
}
|
||||||
|
timeSpentCalculating += delta;
|
||||||
|
|
||||||
Gtk.queueDraw(canvas);
|
Gtk.queueDraw(canvas);
|
||||||
GLib.delay(scene.timeUntilNextStep(),
|
GLib.delay(scene.timeUntilNextStep(),
|
||||||
|
@ -132,4 +138,8 @@ public final class Gtk3BenchmarkStarter {
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Import(name = "currentTimeNano")
|
||||||
|
@Include(value = "support.c", isSystem = false)
|
||||||
|
private static native long currentTimeNano();
|
||||||
}
|
}
|
||||||
|
|
5
samples/benchmark/support.c
Normal file
5
samples/benchmark/support.c
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
static int64_t currentTimeNano() {
|
||||||
|
struct timespec time;
|
||||||
|
clock_gettime(CLOCK_REALTIME, &time);
|
||||||
|
return (int64_t) time.tv_nsec;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user