@@ -104,50 +104,20 @@ public static void main(String[] args) throws Exception {
104104
105105 @ SuppressWarnings ({"ConstantValue" , "LoopConditionNotUpdatedInsideLoop" })
106106 private static void runAtStartup () {
107- // set this to true if you want to hook in profiler say to a forever running JVM
108- int runForMillis = getRunForMillis ();
109107
110- if (runForMillis <= 0 ) {
111- return ;
112- }
113- System .out .printf ("Running initial code before starting the benchmark - runForMillis=%d \n " , runForMillis );
114- System .out .print ("Get your profiler in order and press enter... \n " );
115- readLine ();
116- System .out .print ("Lets go...\n " );
117-
118- long now , then = System .currentTimeMillis ();
119108 ComplexQueryBenchmark complexQueryBenchmark = new ComplexQueryBenchmark ();
120- complexQueryBenchmark .setUp ();
121- do {
122- System .out .printf ("Running queries for %d millis....\n " , System .currentTimeMillis () - then );
123- complexQueryBenchmark .howManyItems = 100 ;
124- complexQueryBenchmark .runManyQueriesToCompletion ();
125- now = System .currentTimeMillis ();
126- } while ((now - then ) < runForMillis );
127- complexQueryBenchmark .tearDown ();
128-
129- System .out .printf ("This took %d millis\n " , System .currentTimeMillis () - then );
130- System .exit (0 );
109+ complexQueryBenchmark .howManyQueries = 5 ;
110+ complexQueryBenchmark .howManyItems = 10 ;
131111
132- }
112+ BenchmarkUtils .runInToolingForSomeTimeThenExit (
113+ complexQueryBenchmark ::setUp ,
114+ complexQueryBenchmark ::runManyQueriesToCompletion ,
115+ complexQueryBenchmark ::tearDown
133116
134- private static void readLine () {
135- BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
136- try {
137- br .readLine ();
138- } catch (IOException e ) {
139- throw new RuntimeException (e );
140- }
117+ );
141118 }
142119
143- private static int getRunForMillis () {
144- String runFor = System .getenv ("runForMillis" );
145- try {
146- return Integer .parseInt (runFor );
147- } catch (NumberFormatException e ) {
148- return -1 ;
149- }
150- }
120+
151121
152122 @ SuppressWarnings ("UnnecessaryLocalVariable" )
153123 private Void runManyQueriesToCompletion () {
0 commit comments