-
Notifications
You must be signed in to change notification settings - Fork 1
/
MemoryStoreBenchmarkTest.java
66 lines (54 loc) · 1.96 KB
/
MemoryStoreBenchmarkTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package com.jparams.store.memory;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import com.carrotsearch.junitbenchmarks.BenchmarkOptions;
import com.carrotsearch.junitbenchmarks.BenchmarkRule;
import com.jparams.store.Store;
import com.jparams.store.index.Index;
import com.jparams.store.model.Person;
import com.jparams.util.JsonTestUtils;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestRule;
import static org.assertj.core.api.Assertions.assertThat;
public class MemoryStoreBenchmarkTest
{
private static final List<Person> TEST_DATA = Arrays.asList(JsonTestUtils.loadResource("/data.json", Person[].class));
@Rule
public TestRule benchmarkRun = new BenchmarkRule();
private List<Person> shuffledTestData;
@Before
public void setUp()
{
shuffledTestData = new ArrayList<>(TEST_DATA);
Collections.shuffle(shuffledTestData);
}
@BenchmarkOptions(benchmarkRounds = 500, warmupRounds = 5)
@Test
public void memoryStoreBenchmark()
{
final Store<Person> store = new MemoryStore<>(shuffledTestData);
final Index<Person> index = store.index(Person::getFirstName);
for (final Person person : TEST_DATA)
{
final List<Person> results = index.get(person.getFirstName());
assertThat(results).contains(person);
}
}
@BenchmarkOptions(benchmarkRounds = 500, warmupRounds = 5)
@Test
public void arrayListBenchmark()
{
for (final Person person : TEST_DATA)
{
final List<Person> results = shuffledTestData.stream()
.filter(p -> p.getFirstName().equals(person.getFirstName()))
.collect(Collectors.toList());
assertThat(results).contains(person);
}
}
}