package dk.ilios.spanner;

import android.support.test.InstrumentationRegistry;

import org.junit.runner.RunWith;

import java.io.File;

import dk.ilios.spanner.example.Utils;
import dk.ilios.spanner.junit.SpannerRunner;

@RunWith(SpannerRunner.class)
public class UnitTestBenchmarks {

    private File filesDir = InstrumentationRegistry.getTargetContext().getFilesDir();
    private File resultsDir = new File(filesDir, "results");
    private File baseLineFile = Utils.copyFromAssets("baseline.json");

    @BenchmarkConfiguration
    public SpannerConfig configuration = new SpannerConfig.Builder()
            .saveResults(resultsDir, UnitTestBenchmarks.class.getCanonicalName() + ".json")
            .useBaseline(baseLineFile)
            .maxFailureLimit(1.0f) // Accept 100% difference, normally should be 10-15%
            .minFailureLimit(1.0f) // Accept 100% difference, normally should be 10-15%
            .meanFailureLimit(1.0f) // Accept 100% difference, normally should be 10-15%
            .medianFailureLimit(1.0f) // Accept 100% difference, normally should be 10-15%
            .uploadResults()
            .build();

    // Public test parameters (value chosen and injected by Experiment)
    @Param(value = {"java.util.Date", "java.lang.Object"})
    public String value;

    // Private fields used by benchmark methods
    private Class testClass;

    @BeforeExperiment
    public void before() {
        try {
            testClass = Class.forName(value);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }

    @AfterExperiment
    public void after() {

    }

    @Benchmark
    public boolean instanceOf(int reps) {
        boolean result = false;
        for (int i = 0; i < reps; i++) {
             result = (testClass instanceof Object);
        }
        return result;
    }

    @Benchmark
    public boolean directComparison(int reps) {
        boolean result = false;
        for (int i = 0; i < reps; i++) {
            result = testClass == Object.class;
        }
        return result;
    }

    @Benchmark
    public boolean equalsTo(int reps) {
        boolean result = false;
        for (int i = 0; i < reps; i++) {
            result = testClass.equals(Object.class);
        }
        return result;
    }
}

@@ -158,21 +158,129 @@
 ner.
-example.Utils
+config.RuntimeInstrumentConfig;%0Aimport dk.ilios.spanner.example.Utils;%0Aimport dk.ilios.spanner.internal.RuntimeInstrument
 ;%0Aim
@@ -795,16 +795,40 @@
 %22.json%22)
+ // Save results to disk
 %0A       
@@ -862,96 +862,38 @@
 ile)
-%0A            .maxFailureLimit(1.0f) // Accept 100%25 difference, normally should be 10-15%25
+ // Compare against a baseline
 %0A   
@@ -903,17 +903,20 @@
       .m
-i
+edia
 nFailure
@@ -925,129 +925,77 @@
 mit(
-1.0f) // Accept 100%25 difference, normally should be 10-15%25%0A            .meanFailureLimit(1.0f) // Accept 100%25 difference,
+Float.MAX_VALUE) // Fail if difference vs. baseline is to big. Should
  nor
@@ -992,39 +992,32 @@
 Should normally 
-should 
 be 10-15%25%0A      
@@ -1001,32 +1001,40 @@
 rmally be 10-15%25
+  (0.15)
 %0A            .me
@@ -1035,114 +1035,105 @@
    .
-medianFailureLimit(1.0f) // Accept 100%25 difference, normally should be 10-15%25%0A            .uploadResults()
+addInstrument(RuntimeInstrumentConfig.defaultConfig()) // Configure how benchmark is run/measured
 %0A   

Remove limit on baseline difference.