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