Skip to content

Commit

Permalink
Speedup verification with parallel streams
Browse files Browse the repository at this point in the history
  • Loading branch information
igorzep committed Nov 7, 2017
1 parent 6efa884 commit f225f49
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 10 additions & 5 deletions src/main/java/band/full/testing/video/core/Plane.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package band.full.testing.video.core;

import static java.lang.Math.abs;
import static java.util.stream.IntStream.range;
import static org.junit.jupiter.api.Assertions.assertFalse;

import java.util.Arrays;
import java.util.stream.IntStream;

/**
* @author Igor Malinin
Expand Down Expand Up @@ -70,14 +72,17 @@ public void verifyRect(int x, int y, int w, int h, int expected,
int x2 = limit(x + w, width);
int y2 = limit(y + h, height);

int count = 0, total = (y2 - y1) * (x2 - x1);
IntStream range = range(y1, y2);
if (x2 - x1 > 64) { // TODO measure when to switch
range = range.parallel();
}

for (int iy = y1; iy < y2; iy++) {
int count = range.map(iy -> {
int base = iy * width;
count += verify(base + x1, base + x2, expected, deviation);
}
return verify(base + x1, base + x2, expected, deviation);
}).sum();

assertFalse(count + maxMisses < total);
assertFalse(count + maxMisses < (y2 - y1) * (x2 - x1));
}

private int verify(int from, int to, int expected, int deviation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ protected void verify(DecoderY4M d, int yMin, boolean redChroma) {

protected void verify(CanvasYCbCr canvas, int yMin, boolean redChroma) {
range(0, ROWS).forEach(row -> {
range(0, COLS).forEach(col -> {
range(0, COLS).parallel().forEach(col -> {
int yCode = yMin + col;
int cCode = canvas.parameters.ACHROMATIC - ROWS / 2 + row;

Expand Down

0 comments on commit f225f49

Please sign in to comment.