How to specify the command line when using a support?

I find that the Google Micro benchmark Caliper project is very interesting, but the documentation still (with the exception of some examples) does not exist at all.

I have two different cases where I need to influence the JVM command line. Caliper starts:

  • I need to set some fixed (ideally alternating between several fixed values) -D parameters
  • I need to specify some fixed values ​​(ideally alternating between several fixed values). JVM options

I saw some discussion about adding such functions, but I could not conclude if it was added or not, and in this case, what did the syntax mean?

Some examples or pointers to a Java doc (assuming it is generally something registered), etc. will be very grateful!

+3
source share
1 answer

To fix a control parameter using a command line argument, use -Dname=value. There is one special parameter named benchmark; these are suffix values ​​for your methods time. If you want to limit the parameters of several values, separate them with commas as follows: -Dname=value1,value2.

To set the JVM parameters, use -Jname=flag1,flag2.

For example, consider this criterion:

public class StringBuilderBenchmark extends SimpleBenchmark {

    @Param({"1", "10", "100"}) private int length;

    public void timeAppendBoolean(int reps) {
        for (int i = 0; i < reps; ++i) {
            StringBuilder sb = new StringBuilder();
            for (int j = 0; j < length; ++j) {
                sb.append(true);
            }
        }
    }

    public void timeAppendChar(int reps) {
        for (int i = 0; i < reps; ++i) {
            StringBuilder sb = new StringBuilder();
            for (int j = 0; j < length; ++j) {
                sb.append('c');
            }
        }
    }
}

5 6 , :

java -cp caliper-0.0.jar:build/classes/test \
    com.google.caliper.Runner examples.StringBuilderBenchmark \
    -Dlength=5,6 -Dbenchmark=AppendBoolean -Jmemory=-Xmx512M,-Xmx16M

:

 0% Scenario{vm=java, trial=0, benchmark=AppendBoolean, length=5, memory=-Xmx512M} 81.79 ns; Οƒ=0.31 ns @ 3 trials
25% Scenario{vm=java, trial=0, benchmark=AppendBoolean, length=6, memory=-Xmx512M} 89.72 ns; Οƒ=2.19 ns @ 10 trials
50% Scenario{vm=java, trial=0, benchmark=AppendBoolean, length=5, memory=-Xmx16M} 111.44 ns; Οƒ=6.01 ns @ 10 trials
75% Scenario{vm=java, trial=0, benchmark=AppendBoolean, length=6, memory=-Xmx16M} 120.23 ns; Οƒ=4.59 ns @ 10 trials

  memory length    ns logarithmic runtime
-Xmx512M      5  81.8 =
-Xmx512M      6  89.7 =======
 -Xmx16M      5 111.4 ========================
 -Xmx16M      6 120.2 =============================

vm: java
trial: 0
benchmark: AppendBoolean
+6

Source: https://habr.com/ru/post/1777610/


All Articles