Skip to content

Instantly share code, notes, and snippets.

@stepancheg
Created March 19, 2012 11:30
Show Gist options
  • Save stepancheg/2108369 to your computer and use it in GitHub Desktop.
Save stepancheg/2108369 to your computer and use it in GitHub Desktop.
/*
* Copyright 2010-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.checkers;
import junit.textui.ResultPrinter;
import junit.textui.TestRunner;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
/**
* @author Stepan Koltsov
*/
public class JetDiagnosticsTestForever {
public static void main(String[] args) {
TestRunner.run(JetDiagnosticsTest.suite());
TestRunner.run(JetDiagnosticsTest.suite());
int limit = args.length > 0 ? Integer.parseInt(args[0]) : Integer.MAX_VALUE;
long total = 0;
long min = Long.MAX_VALUE;
long[] last100 = new long[100];
long[] last10 = new long[10];
for (int i = -100; i < limit; ++i) {
TestRunner runner = new TestRunner();
runner.setPrinter(new ResultPrinter(new PrintStream(new ByteArrayOutputStream())));
long start = System.nanoTime();
runner.doRun(JetDiagnosticsTest.suite());
long d = System.nanoTime() - start;
last100[(i + 100) % 100] = d;
last10[(i + 100) % 10] = d;
long dMs = d / 1000 / 1000;
if (i >= 1) {
total += d;
min = Math.min(min, d);
long avg = total / i / 1000 / 1000;
long avg10 = avg(last10) / 1000 / 1000;
long avg100 = avg(last100) / 1000 / 1000;
long minMs = min / 1000 / 1000;
System.out.println(dMs + "ms; avg=" + avg + "ms; avg10=" + avg10 + "ms; avg100=" + avg100 + "ms; min=" + minMs + "ms; iteration=" + i);
} else {
System.out.println(dMs + "ms; iteration=" + i);
}
}
}
private static long avg(long[] array) {
long sum = 0;
for (long l : array) {
sum += l;
}
return sum / array.length;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment