Skip to content

Instantly share code, notes, and snippets.

@mad
Created February 6, 2021 07:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mad/df729c6a27a7ed224820cdd27209bade to your computer and use it in GitHub Desktop.
Save mad/df729c6a27a7ed224820cdd27209bade to your computer and use it in GitHub Desktop.
package com.bic.jmh;
import java.util.*;
import org.janusgraph.diskstorage.Entry;
import org.janusgraph.diskstorage.EntryList;
import org.janusgraph.diskstorage.util.ByteBufferUtil;
import org.janusgraph.diskstorage.util.StaticArrayBuffer;
import org.janusgraph.diskstorage.util.StaticArrayEntry;
import org.janusgraph.diskstorage.util.StaticArrayEntryList;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.infra.Blackhole;
import org.openjdk.jmh.profile.GCProfiler;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.TimeValue;
@BenchmarkMode(Mode.Throughput)
@State(Scope.Benchmark)
@Fork(jvmArgsAppend = "-Xmx1G")
public class StaticArrayEntryListBenchmark {
List<Entry> entries = new ArrayList<>();
@Param({ "10000", "100000" })
Integer size;
@Param({ "50", "1000", "5000" })
Integer valueSize;
@Setup
public void setup() {
for (int i = 0; i < size; i++) {
StaticArrayBuffer column = StaticArrayEntry.of(ByteBufferUtil.oneByteBuffer(20));
StaticArrayBuffer value = StaticArrayEntry.of(ByteBufferUtil.oneByteBuffer(valueSize));
Entry entry = StaticArrayEntry.of(column, value);
entries.add(entry);
}
}
@Benchmark
public void iterator(Blackhole bh) {
EntryList result = StaticArrayEntryList.ofStaticBuffer(entries.iterator(), StaticArrayEntry.ENTRY_GETTER);
bh.consume(result);
}
@Benchmark
public void iterable(Blackhole bh) {
EntryList result = StaticArrayEntryList.ofStaticBuffer(entries, StaticArrayEntry.ENTRY_GETTER);
bh.consume(result);
}
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.include(StaticArrayEntryListBenchmark.class.getSimpleName())
// .addProfiler(GCProfiler.class)
.forks(1)
.measurementTime(TimeValue.seconds(5))
.warmupIterations(2)
.warmupTime(TimeValue.seconds(1))
.build();
new Runner(opt).run();
}
}
@farodin91
Copy link

@mad wouldn’t be cool to add a benchmark project into the main, which benchmarks some high level functions and some low level functions.

what do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment