Skip to content

Instantly share code, notes, and snippets.

@raphw
Last active August 29, 2015 14:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save raphw/bb23378a8f639a0a99d0 to your computer and use it in GitHub Desktop.
Save raphw/bb23378a8f639a0a99d0 to your computer and use it in GitHub Desktop.
Benchmark of FastList
@State(Scope.Thread)
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public class FastListBenchmark {
private static final int LOAD = 10;
private ArrayList<Object> arrayList;
private FastList<Object> fastList;
private Random random;
@Setup
public void setUp() {
random = new Random();
arrayList = new ArrayList<Object>(LOAD);
fastList = new FastList<Object>(Object.class, LOAD);
for (int i = 0; i < LOAD; i++) {
arrayList.add(new Object());
fastList.add(new Object());
}
}
@Benchmark
public Object testArrayList() {
return arrayList.get(random.nextInt(LOAD));
}
@Benchmark
public Object testFastList() {
return fastList.get(random.nextInt(LOAD));
}
public static void main(String[] args) throws RunnerException {
new Runner(new OptionsBuilder()
.include(FastListBenchmark.class.getSimpleName())
.forks(1)
.build()).run();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment