All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.javasimon.examples.SimonNameGenerationTest Maven / Gradle / Ivy

There is a newer version: 3.4.0
Show newest version
package org.javasimon.examples;

import org.javasimon.SimonManager;
import org.javasimon.utils.SimonUtils;
import org.javasimon.Stopwatch;
import org.javasimon.Split;

/**
 * Compares get/start/stop with static name with the same cycle with name generated every time.
 *
 * @author Richard "Virgo" Richter
 */
public final class SimonNameGenerationTest {
	private static final int LOOP = 100000;

	private static final String NAME = SimonUtils.generateName("-stopwatch", false);

	private SimonNameGenerationTest() {
	}

	/**
	 * Entry point of the demo application.
	 *
	 * @param args command line arguments
	 */
	public static void main(String[] args) {
		// warmup
		Stopwatch tested = SimonManager.getStopwatch(NAME);
		getStartStopTest();
		getStartStopGenerateWithSuffixTest();
		System.out.println("Warm-up complete");

		Stopwatch stopwatch = SimonManager.getStopwatch(null);
		Split split = stopwatch.start();
		tested.reset();
		getStartStopTest();
		System.out.println("\nget+start/stop: " + SimonUtils.presentNanoTime(split.stop()));
		System.out.println("Stopwatch: " + tested);

		tested.reset();
		split = stopwatch.reset().start();
		getStartStopGenerateWithSuffixTest();
		System.out.println("\nget generated+start/stop: " + SimonUtils.presentNanoTime(split.stop()));
		System.out.println("Stopwatch: " + tested);
	}

	private static void getStartStopTest() {
		for (int i = 0; i < LOOP; i++) {
			SimonManager.getStopwatch(NAME).start().stop();
		}
	}

	private static void getStartStopGenerateWithSuffixTest() {
		for (int i = 0; i < LOOP; i++) {
			SimonManager.getStopwatch(SimonUtils.generateName("-stopwatch", false)).start().stop();
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy