Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.lang.management.GarbageCollectorMXBean;
- import java.lang.management.ManagementFactory;
- public class Main {
- public static class Test {
- long t;
- long[] tA = new long[1024*1024];
- public Test(long t) {
- this.t = t;
- this.tA[(int)t] = t;
- }
- public long getTa() {
- return this.tA[(int)this.t];
- }
- }
- public static class Res {
- long times, ms;
- public Res(long times, long ms) {
- this.times = times;
- this.ms = ms;
- }
- }
- public static Res getGCStats() {
- long totalGarbageCollections = 0;
- long garbageCollectionTime = 0;
- for(GarbageCollectorMXBean gc : ManagementFactory.getGarbageCollectorMXBeans()) {
- long count = gc.getCollectionCount();
- if(count >= 0) {
- totalGarbageCollections += count;
- }
- long time = gc.getCollectionTime();
- if(time >= 0) {
- garbageCollectionTime += time;
- }
- }
- return new Res(totalGarbageCollections, garbageCollectionTime);
- }
- public static void main(String[] args) {
- Test t = new Test(1);
- System.out.println("Start");
- while (t.t < 10000L) {
- t = new Test(t.getTa()+1);
- }
- var res = getGCStats();
- System.out.println("Total collections: "+res.times);
- System.out.println("Total time in ms: "+res.ms);
- System.out.println("MS per run: "+((double)res.ms/(double)res.times));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement