Initial commit of LinearRegression class
This commit is contained in:
parent
3c8c692b16
commit
8050170ee3
5 changed files with 306 additions and 80 deletions
57
test/zutil/benchmark/AnonymousFunctionBenchmark.java
Executable file
57
test/zutil/benchmark/AnonymousFunctionBenchmark.java
Executable file
|
|
@ -0,0 +1,57 @@
|
|||
package zutil.benchmark;
|
||||
|
||||
import com.carrotsearch.junitbenchmarks.BenchmarkRule;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
public class AnonymousFunctionBenchmark {
|
||||
public static final int TEST_EXECUTIONS = 500;
|
||||
|
||||
@Rule
|
||||
public BenchmarkRule benchmarkRun = new BenchmarkRule();
|
||||
|
||||
|
||||
private int[] array = new int[100_000];
|
||||
|
||||
|
||||
@Test
|
||||
public void functionLoop() {
|
||||
for(int k=0; k<TEST_EXECUTIONS; k++) {
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
array[i] = new CalcFunc(){
|
||||
public int calc(int i){
|
||||
return i+1;
|
||||
}
|
||||
}.calc(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void preFunctionLoop() {
|
||||
CalcFunc func = new CalcFunc(){
|
||||
public int calc(int i){
|
||||
return i+1;
|
||||
}
|
||||
};
|
||||
|
||||
for(int k=0; k<TEST_EXECUTIONS; k++) {
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
array[i] = func.calc(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rawLoops(){
|
||||
for(int k=0; k<TEST_EXECUTIONS; k++) {
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
array[i] = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private interface CalcFunc{
|
||||
int calc(int i);
|
||||
}
|
||||
}
|
||||
|
|
@ -11,30 +11,51 @@ public class LoopBenchmark {
|
|||
public BenchmarkRule benchmarkRun = new BenchmarkRule();
|
||||
|
||||
|
||||
private int[] matrix = new int[100_000];
|
||||
private int[] matrix2 = new int[50_000];
|
||||
private int[] array1 = new int[100_000];
|
||||
private int[] array2 = new int[50_000];
|
||||
|
||||
|
||||
@Test
|
||||
public void oneLoop() {
|
||||
public void writeArrayOneLoop() {
|
||||
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;
|
||||
for (int i = 0; i < Math.max(array1.length, array1.length); i++) {
|
||||
if (i < array1.length)
|
||||
array1[i] = i;
|
||||
if (i < array2.length)
|
||||
array2[i] = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void twoLoops(){
|
||||
public void writeArraySeparateLoops(){
|
||||
for(int k=0; k<TEST_EXECUTIONS; k++) {
|
||||
for (int i = 0; i < matrix.length; i++) {
|
||||
matrix[i] = i;
|
||||
for (int i = 0; i < array1.length; i++) {
|
||||
array1[i] = i;
|
||||
}
|
||||
for (int j = 0; j < matrix2.length; j++) {
|
||||
matrix2[j] = j;
|
||||
for (int j = 0; j < array2.length; j++) {
|
||||
array2[j] = j;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void readArrayLoop() {
|
||||
int sum = 0;
|
||||
for(int k=0; k<TEST_EXECUTIONS; k++) {
|
||||
for (int i = 0; i < array1.length; i++) {
|
||||
sum += array1[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readArrayForeach() {
|
||||
int sum = 0;
|
||||
for(int k=0; k<TEST_EXECUTIONS; k++) {
|
||||
for (int i : array1) {
|
||||
sum += array1[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue