Updated benchmark jar
This commit is contained in:
parent
5cffdc49d1
commit
1cd48ac2ff
5 changed files with 103 additions and 4 deletions
BIN
lib/junit-benchmarks-0.7.0.jar → lib/junit-benchmarks-0.7.2.jar
Normal file → Executable file
BIN
lib/junit-benchmarks-0.7.0.jar → lib/junit-benchmarks-0.7.2.jar
Normal file → Executable file
Binary file not shown.
42
test/zutil/benchmark/LoopBenchmark.java
Executable file
42
test/zutil/benchmark/LoopBenchmark.java
Executable file
|
|
@ -0,0 +1,42 @@
|
|||
package zutil.benchmark;
|
||||
|
||||
import com.carrotsearch.junitbenchmarks.BenchmarkRule;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import zutil.StringUtil;
|
||||
|
||||
public class LoopBenchmark {
|
||||
public static final int TEST_EXECUTIONS = 500;
|
||||
|
||||
@Rule
|
||||
public BenchmarkRule benchmarkRun = new BenchmarkRule();
|
||||
|
||||
|
||||
private int[] matrix = new int[100_000];
|
||||
private int[] matrix2 = new int[50_000];
|
||||
|
||||
|
||||
@Test
|
||||
public void oneLoop() {
|
||||
for(int k=0; k<TEST_EXECUTIONS; k++) {
|
||||
for (int i = 0; i < Math.max(matrix.length, matrix.length); i++) {
|
||||
if (i < matrix.length)
|
||||
matrix[i] = i;
|
||||
if (i < matrix2.length)
|
||||
matrix2[i] = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void twoLoops(){
|
||||
for(int k=0; k<TEST_EXECUTIONS; k++) {
|
||||
for (int i = 0; i < matrix.length; i++) {
|
||||
matrix[i] = i;
|
||||
}
|
||||
for (int j = 0; j < matrix2.length; j++) {
|
||||
matrix2[j] = j;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
59
test/zutil/benchmark/StringSplitBenchmark.java
Executable file
59
test/zutil/benchmark/StringSplitBenchmark.java
Executable file
|
|
@ -0,0 +1,59 @@
|
|||
package zutil.benchmark;
|
||||
|
||||
import com.carrotsearch.junitbenchmarks.BenchmarkOptions;
|
||||
import com.carrotsearch.junitbenchmarks.BenchmarkRule;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Created by Ziver on 2016-07-07.
|
||||
*/
|
||||
public class StringSplitBenchmark {
|
||||
public static final int TEST_EXECUTIONS = 200000;
|
||||
|
||||
@Rule
|
||||
public BenchmarkRule benchmarkRun = new BenchmarkRule();
|
||||
|
||||
private static String delimiter = ",";
|
||||
private static String str = "aaa,aaaaaa,aaaaaa,aa,a,a,a,bb,bbb,aaaaaaaaa,a,a,aaa";
|
||||
|
||||
|
||||
@Test
|
||||
public void stringSplit(){
|
||||
for(int i=0; i<TEST_EXECUTIONS; i++)
|
||||
assertSplit(str.split(delimiter));
|
||||
}
|
||||
|
||||
public static Pattern pattern = Pattern.compile(delimiter);
|
||||
@Test
|
||||
public void patternSplit(){
|
||||
for(int i=0; i<TEST_EXECUTIONS; i++)
|
||||
assertSplit(pattern.split(str));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void substring(){
|
||||
for(int i=0; i<TEST_EXECUTIONS; i++) {
|
||||
ArrayList<String> splitList = new ArrayList<>();
|
||||
int from = 0, to = 0;
|
||||
while (to >= 0) {
|
||||
to = str.indexOf(delimiter, from + 1);
|
||||
if (to < 0)
|
||||
splitList.add(str.substring(from));
|
||||
else
|
||||
splitList.add(str.substring(from, to));
|
||||
from = to;
|
||||
}
|
||||
assertSplit(splitList.toArray(new String[splitList.size()]));
|
||||
}
|
||||
}
|
||||
|
||||
public void assertSplit(String[] str){
|
||||
assertEquals(13,str.length);
|
||||
}
|
||||
}
|
||||
|
|
@ -57,7 +57,7 @@ public class JSONSerializerBenchmark {
|
|||
TestClass targetObj = (TestClass) in.readObject();
|
||||
in.close();
|
||||
|
||||
assertEquals( sourceObj, targetObj );
|
||||
TestClass.assertEquals( sourceObj, targetObj );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -68,7 +68,7 @@ public class JSONSerializerBenchmark {
|
|||
|
||||
TestClass targetObj = JSONSerializerTest.sendReceiveObject(sourceObj);
|
||||
|
||||
assertEquals( sourceObj, targetObj );
|
||||
TestClass.assertEquals( sourceObj, targetObj );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -186,8 +186,6 @@ public class JSONSerializerTest{
|
|||
out.close();
|
||||
|
||||
String data = bout.toString();
|
||||
System.out.println(data);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue