Skip to content

Instantly share code, notes, and snippets.

@rxin
Created Jul 21, 2015
Embed
What would you like to do?
NaN double vs float testing
package com.databricks.unsafe.util.benchmark;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;
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;
@State(Scope.Benchmark)
public class NaNTesting {
@Benchmark
public boolean doubleNaN() {
return Double.isNaN(Float.NaN);
}
@Benchmark
public boolean floatNaN() {
return Float.isNaN(Float.NaN);
}
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.include(BinarySearch.class.getSimpleName())
.warmupIterations(5)
.measurementIterations(5)
.forks(2)
.jvmArgs("-ea")
.build();
new Runner(opt).run();
}
}
Benchmark Mode Cnt Score Error Units
NaNTesting.doubleNaN thrpt 4 470522065.357 ± 64048838.498 ops/s
NaNTesting.floatNaN thrpt 4 465024924.176 ± 66806183.042 ops/s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment