Created
July 21, 2015 00:39
-
-
Save rxin/655106e0d52e7ff780d3 to your computer and use it in GitHub Desktop.
NaN double vs float testing
This file contains 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 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(); | |
} | |
} |
This file contains 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
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