Created
January 27, 2015 02:43
-
-
Save ennerf/e4078e0aa9c41fa3de49 to your computer and use it in GitHub Desktop.
JMH benchmark for https://github.com/google/flatbuffers/pull/134
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package us.hebi.flatbuffers; | |
import org.openjdk.jmh.annotations.*; | |
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.VerboseMode; | |
import java.util.concurrent.TimeUnit; | |
/** | |
* @author Florian Enner < florian @ hebirobotics.com > | |
* @since 26 Jan 2015 | |
*/ | |
@BenchmarkMode(Mode.AverageTime) | |
@OutputTimeUnit(TimeUnit.NANOSECONDS) | |
@Fork(2) | |
@Warmup(iterations = 20) | |
@Measurement(iterations = 20) | |
@State(Scope.Thread) | |
public class BooleanOrderBenchmark { | |
public static void main(String[] args) throws RunnerException { | |
Options options = new OptionsBuilder() | |
.include(".*" + BooleanOrderBenchmark.class.getSimpleName() + ".*") | |
.verbosity(VerboseMode.NORMAL) | |
.build(); | |
new Runner(options).run(); | |
} | |
/** | |
* OS: Windows 8.1 | |
* JDK: Oracle JDK 1.8.0_20-b26 | |
* CPU: Intel i5-3427U @ 1.80 Ghz | |
* <p/> | |
* Benchmark Mode Samples Score Score error Units | |
* u.h.f.BooleanOrderBenchmark.forceDefaultsFirst_false avgt 40 2.647 0.009 ns/op | |
* u.h.f.BooleanOrderBenchmark.forceDefaultsLast_false avgt 40 2.657 0.018 ns/op | |
* u.h.f.BooleanOrderBenchmark.forceDefaultsFirst_true avgt 40 2.825 0.027 ns/op | |
* u.h.f.BooleanOrderBenchmark.forceDefaultsLast_true avgt 40 2.844 0.036 ns/op | |
*/ | |
boolean forceDefaultsTrue = true; | |
boolean forceDefaultsFalse = false; | |
int defaultValue = 0; | |
int value = 0; | |
@Benchmark | |
public boolean forceDefaultsFirst_false() { | |
value = (value + 1) & 0x7; | |
return forceDefaultsFalse || defaultValue != value; | |
} | |
@Benchmark | |
public boolean forceDefaultsLast_false() { | |
value = (value + 1) & 0x7; | |
return defaultValue != value || forceDefaultsFalse; | |
} | |
@Benchmark | |
public boolean forceDefaultsFirst_true() { | |
value = (value + 1) & 0x7; | |
return forceDefaultsTrue || defaultValue != value; | |
} | |
@Benchmark | |
public boolean forceDefaultsLast_true() { | |
value = (value + 1) & 0x7; | |
return defaultValue != value || forceDefaultsTrue; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It assumes that every 8th call evaluates false for "defaultValue != value"