Created
September 29, 2016 19:40
-
-
Save qwwdfsad/fd47ef9b795891496e989f32ca24851a to your computer and use it in GitHub Desktop.
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 org.qwwdfsad.benchmarks | |
import org.openjdk.jmh.annotations.* | |
import java.util.concurrent.TimeUnit | |
/** | |
* @author Tolstopyatov Vsevolod | |
* @since 29/09/16 | |
*/ | |
@Fork(value = 2) //jvmArgsAppend = arrayOf("-XX:TieredStopAtLevel=1")) | |
@Measurement(iterations = 10) | |
@Warmup(iterations = 15) | |
@State(Scope.Benchmark) | |
@BenchmarkMode(Mode.AverageTime) | |
@OutputTimeUnit(TimeUnit.NANOSECONDS) | |
open class ContainsBenchmark() { | |
var longValue: Long = 1L | |
var intValue: Int = 1 | |
var doubleValue: Double = 1.0 | |
@Setup(Level.Iteration) | |
fun init() { | |
longValue = 2L | |
intValue = 2 | |
doubleValue = 2.0 | |
} | |
@Benchmark | |
fun intIn(): Boolean { | |
return intValue in 1..10 | |
} | |
@Benchmark | |
fun longIn(): Boolean { | |
return longValue in 1L..10L | |
} | |
@Benchmark | |
fun doubleIn(): Boolean { | |
return doubleValue in 1.0..10.0 | |
} | |
@Benchmark | |
fun intCompare(): Boolean { | |
val i = intValue | |
return 1 <= i && i <= 10 | |
} | |
@Benchmark | |
fun longCompare(): Boolean { | |
val i = longValue | |
return 1L <= i && i <= 10L | |
} | |
@Benchmark | |
fun doubleCompare(): Boolean { | |
val i = doubleValue | |
return 1.0 <= i && i <= 10.0 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment