-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
49 changed files
with
2,597 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
stream/src/jmh/java/com/annimon/stream/IndexedBenchmarks.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package com.annimon.stream; | ||
|
||
import com.annimon.stream.function.IndexedIntPredicate; | ||
import com.annimon.stream.function.IndexedPredicate; | ||
import com.annimon.stream.function.IntUnaryOperator; | ||
import com.annimon.stream.function.UnaryOperator; | ||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.annotations.Param; | ||
import org.openjdk.jmh.annotations.Scope; | ||
import org.openjdk.jmh.annotations.Setup; | ||
import org.openjdk.jmh.annotations.State; | ||
import org.openjdk.jmh.infra.Blackhole; | ||
|
||
@State(Scope.Benchmark) | ||
public class IndexedBenchmarks { | ||
|
||
private int[] input; | ||
|
||
@Param({"10000000"}) | ||
public int size; | ||
|
||
@Setup | ||
public void setup() { | ||
input = new int[size]; | ||
for (int i = 0; i < size; i++) { | ||
input[i] = i % 10; | ||
} | ||
} | ||
|
||
@Benchmark | ||
public void boxedFilterIndexed(Blackhole bh) { | ||
bh.consume(IntStream.of(input) | ||
.boxed() | ||
.filterIndexed(new IndexedPredicate<Integer>() { | ||
@Override | ||
public boolean test(int index, Integer value) { | ||
return index != value; | ||
} | ||
}) | ||
.count()); | ||
} | ||
|
||
@Benchmark | ||
public void primitiveFilterIndexed(Blackhole bh) { | ||
bh.consume(IntStream.of(input) | ||
.filterIndexed(new IndexedIntPredicate() { | ||
@Override | ||
public boolean test(int index, int value) { | ||
return index != value; | ||
} | ||
}) | ||
.count()); | ||
} | ||
|
||
|
||
@Benchmark | ||
public void boxedFilterIndexedAndMap(Blackhole bh) { | ||
bh.consume(IntStream.of(input) | ||
.boxed() | ||
.filterIndexed(new IndexedPredicate<Integer>() { | ||
@Override | ||
public boolean test(int index, Integer value) { | ||
return index % 5 == 0; | ||
} | ||
}) | ||
.map(new UnaryOperator<Integer>() { | ||
@Override | ||
public Integer apply(Integer value) { | ||
return value * 7; | ||
} | ||
}) | ||
.filterIndexed(new IndexedPredicate<Integer>() { | ||
@Override | ||
public boolean test(int index, Integer value) { | ||
return index != value; | ||
} | ||
}) | ||
.count()); | ||
} | ||
|
||
@Benchmark | ||
public void primitiveFilterIndexedAndMap(Blackhole bh) { | ||
bh.consume(IntStream.of(input) | ||
.filterIndexed(new IndexedIntPredicate() { | ||
@Override | ||
public boolean test(int index, int value) { | ||
return index % 5 == 0; | ||
} | ||
}) | ||
.map(new IntUnaryOperator() { | ||
@Override | ||
public int applyAsInt(int value) { | ||
return value * 7; | ||
} | ||
}) | ||
.filterIndexed(new IndexedIntPredicate() { | ||
@Override | ||
public boolean test(int index, int value) { | ||
return index != value; | ||
} | ||
}) | ||
.count()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.