Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Native benchmark: iteration counter overflow #179

Open
fzhinkin opened this issue Jan 14, 2024 · 0 comments
Open

Native benchmark: iteration counter overflow #179

fzhinkin opened this issue Jan 14, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@fzhinkin
Copy link
Contributor

During the warmup phase, the native benchmarks executor estimates the repetitions of benchmarked function calls within each measurement iteration. That number is stored in an integer variable. Given a fast enough benchmark and long enough iterationTime, the repetitions counter (called iterations in the code) may overflow, leading to negative results in a report.

@State(Scope.Benchmark)
@BenchmarkMode(Mode.AverageTime)
open class TestBenchmark {
    private var x = 123L

    fun nextValue(): Long {
        val r = x
        x = -1 * (x * 6364136223846793005 + 1442695040888963407)
        return r
    }
    
    @Benchmark
    fun signBenchmark(): Int = nextValue().sign    
}
    configurations {
        named("main") {
            warmups = 2
            iterations = 3
            iterationTime = 40 * 4
            iterationTimeUnit = "sec"
            outputTimeUnit = "ns"
        }
    }

Results:

Warm-up #0: -79-0.538163 ns/op
Warm-up #1: -81-0.545774 ns/op
Iteration #0: 0-0.000000 ns/op
Iteration #1: 0 ns/op
Iteration #2: 0-0.000000 ns/op
  Success:   ~ 0-0.000000 ns/op ±-98-0.00%
@fzhinkin fzhinkin added the bug Something isn't working label Jan 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant