[TEST] Improve performance of MockBigArray MockPageRecycler
This commit is contained in:
parent
5d611a9098
commit
efb749936b
|
@ -294,9 +294,7 @@ public class MockBigArrays extends BigArrays {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void randomizeContent(long from, long to) {
|
protected void randomizeContent(long from, long to) {
|
||||||
for (long i = from; i < to; ++i) {
|
fill(from, to, (byte) random.nextInt(1 << 8));
|
||||||
set(i, (byte) random.nextInt(1 << 8));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -342,9 +340,7 @@ public class MockBigArrays extends BigArrays {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void randomizeContent(long from, long to) {
|
protected void randomizeContent(long from, long to) {
|
||||||
for (long i = from; i < to; ++i) {
|
fill(from, to, random.nextInt());
|
||||||
set(i, random.nextInt());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -385,9 +381,7 @@ public class MockBigArrays extends BigArrays {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void randomizeContent(long from, long to) {
|
protected void randomizeContent(long from, long to) {
|
||||||
for (long i = from; i < to; ++i) {
|
fill(from, to, random.nextLong());
|
||||||
set(i, random.nextLong());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -428,9 +422,7 @@ public class MockBigArrays extends BigArrays {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void randomizeContent(long from, long to) {
|
protected void randomizeContent(long from, long to) {
|
||||||
for (long i = from; i < to; ++i) {
|
fill(from, to, (random.nextFloat() - 0.5f) * 1000);
|
||||||
set(i, (random.nextFloat() - 0.5f) * 1000);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -471,9 +463,7 @@ public class MockBigArrays extends BigArrays {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void randomizeContent(long from, long to) {
|
protected void randomizeContent(long from, long to) {
|
||||||
for (long i = from; i < to; ++i) {
|
fill(from, to, (random.nextDouble() - 0.5) * 1000);
|
||||||
set(i, (random.nextDouble() - 0.5) * 1000);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -32,6 +32,7 @@ import org.elasticsearch.test.TestCluster;
|
||||||
import org.elasticsearch.threadpool.ThreadPool;
|
import org.elasticsearch.threadpool.ThreadPool;
|
||||||
|
|
||||||
import java.lang.reflect.Array;
|
import java.lang.reflect.Array;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
@ -85,11 +86,21 @@ public class MockPageCacheRecycler extends PageCacheRecycler {
|
||||||
throw new IllegalStateException("Releasing a page that has not been acquired");
|
throw new IllegalStateException("Releasing a page that has not been acquired");
|
||||||
}
|
}
|
||||||
final T ref = v();
|
final T ref = v();
|
||||||
for (int i = 0; i < Array.getLength(ref); ++i) {
|
if (ref instanceof Object[]) {
|
||||||
if (ref instanceof Object[]) {
|
Arrays.fill((Object[])ref, 0, Array.getLength(ref), null);
|
||||||
Array.set(ref, i, null);
|
} else if (ref instanceof byte[]) {
|
||||||
} else {
|
Arrays.fill((byte[])ref, 0, Array.getLength(ref), (byte) random.nextInt(256));
|
||||||
Array.set(ref, i, (byte) random.nextInt(256));
|
} else if (ref instanceof long[]) {
|
||||||
|
Arrays.fill((long[])ref, 0, Array.getLength(ref), random.nextLong());
|
||||||
|
} else if (ref instanceof int[]) {
|
||||||
|
Arrays.fill((int[])ref, 0, Array.getLength(ref), random.nextInt());
|
||||||
|
} else if (ref instanceof double[]) {
|
||||||
|
Arrays.fill((double[])ref, 0, Array.getLength(ref), random.nextDouble() - 0.5);
|
||||||
|
} else if (ref instanceof float[]) {
|
||||||
|
Arrays.fill((float[])ref, 0, Array.getLength(ref), random.nextFloat() - 0.5f);
|
||||||
|
} else {
|
||||||
|
for (int i = 0; i < Array.getLength(ref); ++i) {
|
||||||
|
Array.set(ref, i, (byte) random.nextInt(256));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return v.release();
|
return v.release();
|
||||||
|
@ -112,7 +123,7 @@ public class MockPageCacheRecycler extends PageCacheRecycler {
|
||||||
public V<byte[]> bytePage(boolean clear) {
|
public V<byte[]> bytePage(boolean clear) {
|
||||||
final V<byte[]> page = super.bytePage(clear);
|
final V<byte[]> page = super.bytePage(clear);
|
||||||
if (!clear) {
|
if (!clear) {
|
||||||
random.nextBytes(page.v());
|
Arrays.fill(page.v(), 0, page.v().length, (byte)random.nextInt(1<<8));
|
||||||
}
|
}
|
||||||
return wrap(page);
|
return wrap(page);
|
||||||
}
|
}
|
||||||
|
@ -121,9 +132,7 @@ public class MockPageCacheRecycler extends PageCacheRecycler {
|
||||||
public V<int[]> intPage(boolean clear) {
|
public V<int[]> intPage(boolean clear) {
|
||||||
final V<int[]> page = super.intPage(clear);
|
final V<int[]> page = super.intPage(clear);
|
||||||
if (!clear) {
|
if (!clear) {
|
||||||
for (int i = 0; i < page.v().length; ++i) {
|
Arrays.fill(page.v(), 0, page.v().length, random.nextInt());
|
||||||
page.v()[i] = random.nextInt();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return wrap(page);
|
return wrap(page);
|
||||||
}
|
}
|
||||||
|
@ -132,9 +141,7 @@ public class MockPageCacheRecycler extends PageCacheRecycler {
|
||||||
public V<long[]> longPage(boolean clear) {
|
public V<long[]> longPage(boolean clear) {
|
||||||
final V<long[]> page = super.longPage(clear);
|
final V<long[]> page = super.longPage(clear);
|
||||||
if (!clear) {
|
if (!clear) {
|
||||||
for (int i = 0; i < page.v().length; ++i) {
|
Arrays.fill(page.v(), 0, page.v().length, random.nextLong());
|
||||||
page.v()[i] = random.nextLong();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return wrap(page);
|
return wrap(page);
|
||||||
}
|
}
|
||||||
|
@ -143,9 +150,7 @@ public class MockPageCacheRecycler extends PageCacheRecycler {
|
||||||
public V<double[]> doublePage(boolean clear) {
|
public V<double[]> doublePage(boolean clear) {
|
||||||
final V<double[]> page = super.doublePage(clear);
|
final V<double[]> page = super.doublePage(clear);
|
||||||
if (!clear) {
|
if (!clear) {
|
||||||
for (int i = 0; i < page.v().length; ++i) {
|
Arrays.fill(page.v(), 0, page.v().length, random.nextDouble() - 0.5);
|
||||||
page.v()[i] = random.nextDouble() - 0.5;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return wrap(page);
|
return wrap(page);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue