package com.carrotsearch.hppc;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import com.carrotsearch.hppc.cursors.FloatCursor;
import com.carrotsearch.hppc.mutables.IntHolder;
import com.carrotsearch.hppc.procedures.FloatProcedure;
import com.carrotsearch.junitbenchmarks.AbstractBenchmark;
import com.carrotsearch.junitbenchmarks.BenchmarkOptions;
import com.carrotsearch.junitbenchmarks.h2.BenchmarkHistoryChart;
import com.carrotsearch.junitbenchmarks.h2.BenchmarkMethodChart;
/**
* Benchmark tests for {@link FloatArrayList}.
*/
@BenchmarkHistoryChart(filePrefix="CLASSNAME.history", maxRuns=50)
@BenchmarkMethodChart(filePrefix="CLASSNAME.methods")
@BenchmarkOptions(callgc = false, warmupRounds = 5, benchmarkRounds = 10)
/* removeIf:applied. */
public class FloatArrayListBenchmark extends AbstractBenchmark
{
public static final int CELLS = (1024 * 1024) * 50;
private static FloatArrayList singleton;
private FloatArrayList list = (FloatArrayList) singleton;
private static final /* replaceIf:applied. */ float /* end */ defValue = ((float) 0);
/* */
@BeforeClass
public static void before()
{
singleton = new FloatArrayList();
singleton.resize(CELLS);
}
@AfterClass
public static void cleanup()
{
singleton = null;
}
/* */
@Test
public void testSimpleGetLoop() throws Exception
{
final FloatArrayList list = this.list;
final int max = list.size();
int count = 0;
for (int i = 0; i < max; i++)
{
if (list.get(i) != defValue)
count++;
}
Assert.assertEquals(0, count);
}
/* */
@Test
public void testDirectBufferLoop() throws Exception
{
final int size = list.size();
final float [] buffer = list.buffer;
int count = 0;
for (int i = 0; i < size; i++)
{
if (buffer[i] != defValue)
count++;
}
Assert.assertEquals(0, count);
}
/* */
@Test
public void testIterableCursor() throws Exception
{
int count = 0;
for (FloatCursor c : list)
{
if (c.value != defValue)
count++;
}
Assert.assertEquals(0, count);
}
/* */
@Test
public void testWithProcedureClosure()
{
final IntHolder count = new IntHolder();
list.forEach(new FloatProcedure() {
public void apply(float v)
{
if (v != defValue)
count.value++;
}
});
Assert.assertEquals(0, count.value);
}
/* */
@Test
public void testDirectBufferWithNewFor() throws Exception
{
int count = 0;
for (float c : (float[]) list.buffer)
{
if (defValue != (float) c)
count++;
}
Assert.assertEquals(0, count);
}
}