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

com.fillumina.performance.PerformanceTimerFactory Maven / Gradle / Ivy

Go to download

Configurable tool to easily compare performances of different code snippets and to take performance telemetry of a running application.

The newest version!
package com.fillumina.performance;

import com.fillumina.performance.producer.timer.MultiThreadPerformanceExecutorBuilder;
import com.fillumina.performance.producer.timer.PerformanceTimer;
import com.fillumina.performance.producer.timer.SingleThreadPerformanceExecutor;

/**
 * Static factory helper to create a {@link PerformanceTimer}.
 * 

* There are two ways of using this API: *

    *
  • Using a * fluent * interface that starts by creating the needed * {@link PerformanceTimer} using this static factory (or by constructing * one directly);
  • *
  • Using one of the templates in the * {@link com.fillumina.performance.template} package.
  • *
* The first choice allows for better customizations while the second is * probably easier to use. * * @see * Java theory and practice: Anatomy of a flawed microbenchmark * (Brian Goetz) * * * @see * Java theory and practice: Dynamic compilation and performance measurement * (Brian Goetz) * * * @author Francesco Illuminati */ public class PerformanceTimerFactory { /** * Creates a single threaded performance test. *
    PerformanceTimerFactory
       .createSingleThreaded()

       .addTest("one", new Runnable() {
           public void run() {
               // define here the test
           }
       })
       .addTest("two", new Runnable() {
           public void run() {
               // define here the test
           }
       })

       .instrumentedBy(AutoProgressionPerformanceInstrumenter.builder()
           .setMaxStandardDeviation(1)
           .buildMultiThreadPerformanceExecutor())

       .execute()
       .use(AssertPerformance.withTolerance(5F)
                .assertTest("one").sameAs("two"));
     * 
*/ public static PerformanceTimer createSingleThreaded() { return new PerformanceTimer(new SingleThreadPerformanceExecutor()); } /** * Creates a {@link PerformanceTimer} with a multi threaded executor * using a builder (don't forget to call * {@link MultiThreadPerformanceExecutorBuilder#build()} * at the end of the builder). * Each test will be executed in a multi threaded * environment (so take extra care about thread safety, especially with * the test's fields). *
    PerformanceTimerFactory.getMultiThreadedBuilder()
            .setConcurrencyLevel(Runtime.getRuntime().availableProcessors())
            .build()

            .addTest("one", new Runnable() {
                public void run() {
                    // define here the test
                }
            })
            .addTest("two", new Runnable() {
                public void run() {
                    // define here the test
                }
            })

            .instrumentedBy(AutoProgressionPerformanceInstrumenter.builder()
                .setMaxStandardDeviation(3)
                .buildMultiThreadPerformanceExecutor())

            .execute()
            .use(AssertPerformance.withTolerance(5F)
                .assertTest("one").sameAs("two"));
     * 
*/ public static MultiThreadPerformanceExecutorBuilder getMultiThreadedBuilder() { return new MultiThreadPerformanceExecutorBuilder(); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy