Giter Site home page Giter Site logo

AutoJMH

AutoJMH is a tool that takes as input one segment of code (belonging to an existing program) and one training execution (could be a unit test run for example) and builds full JMH microbenchmark for the segment. The tool generates the JMH class and then places the segment code inside the wrapper method, fully generating the microbenchmark. AutoJMH also initializes the variables of the microbenchmark and perform a series of analysis to automatically avoid common microbenchmarking pitfalls.

For example, suppose that given the following program we want to extract the int a = (int)Math.log(n * n / 2) * myBubbleSort(list) into a microbenchmark:

private static int gnomesort(List<Integer> ar) {
    int i = 0; int k = 0;
    while (i < ar.size()) {
        if (i == 0 || ar.get(i-1) <= ar.get(i)) i++;
        else { int tmp = ar.get(i); ar.set(i, ar.get(i-1)); ar.set(--i, tmp); }
        k++;
    }
    return k;
}

//Sorts the list, add 'n' and returns the number 
//of steps needed to sort the list and do some math with it
public int addAndSorted(List<Integer> list, int n) {
	n = n < 1 ? 1 : n;
    list.add(n);

    /** @bench-this */
    int a = (int)Math.log(n * n / 2) * myBubbleSort(list);
    
    return a;  
}

AutoJMH will generate the following microbenchmark for it:

@State(Scope.Thread)
public class org_packagename_YourClassName_348 {
    int n;
    List<Integer> list;
    List<Integer> list___reset;

    private static int gnomesort(List<Integer> ar) {
        int i = 0; int k = 0;
        while (i < ar.size()) {
            if (i == 0 || ar.get(i-1) <= ar.get(i)) i++;
            else { int tmp = ar.get(i); ar.set(i, ar.get(i-1)); ar.set(--i, tmp); }
            k++;
        }
        return k;
    }

    @Setup
    public void setup() {
        Loader loader_348 = new Loader("usr/data/YourClassName_348");
		      list___reset = loader_348.readIntegerList();
        list = loader_348.readEmptyList(); 
		      n = loader_348.readInt();
    }

    @Setup(Level.Invocation)
    public void resetCode() {
        list.clear(); list.addAll(list___reset);
    }

    @Benchmark
    public int doBenchmark() {
        int a = (int)Math.log(n * n / 2) * gnomesort(list);
        return a;
    }
}

The tool is able to extract the code and all its dependencies (method, variables), provide initialization values, avoid DCE and keep the microbenchmark in its one stable state.

AutoJMH Dev Team's Projects

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.