/** * Call @a runnable.run() and time how long it takes to run. */ public static void timeRun(Runnable runnable, String testName) { startTiming(); runnable.run(); stopTiming(); // Store the execution times into the results map. mResultsMap.put(testName, mExecutionTime); }
/** * This template method starts the Java 8 stream processing to * search the list of input strings for the given phrases to find. */ @Override protected void initiateStream() { // Create a new barrier for this iteration cycle. mExitBarrier = new CountDownLatch(1); // Execute the test and time how long it runs. List<List<SearchResults>> results = RunTimer.timeRun(() -> processStream(), TAG); // Print the results. printResults(TAG, results); // Indicate all computations in this iteration are done. try { mExitBarrier.countDown(); } catch (Exception ex) { throw new RuntimeException(ex); } }
/** * Create/run appropriate type of StreamGang to search for phases. */ private static void runTests(List<String> phaseList, List<List<CharSequence>> inputData) { // Warm up the fork-join pool. warmUpForkJoinPool(phaseList, inputData); // Run all the SearchStreamGang tests. for (TestsToRun test : TestsToRun.values()) { System.out.println("Starting " + test); // Use the factory method to make the appropriate // SearchStreamGang. SearchStreamGang streamGang = makeSearchStreamGang(phaseList, inputData, test); // Ensure nothing weird happened.. assert streamGang != null; // Execute the test. streamGang.run(); // Run the garbage collector to free up memory and // minimize timing perturbations on each test. System.gc(); System.out.println("Ending " + test); } // Sort and display all the timing results. System.out.println(RunTimer.getTimingResults()); }
/** * Call @a supplier.get() and time how long it takes to run. * * @return The result returned by @a supplier.get() */ public static <U> U timeRun(Supplier<U> supplier, String testName) { startTiming(); U result = supplier.get(); stopTiming(); // Store the execution times into the results map. mResultsMap.put(testName, mExecutionTime); return result; }