How to evaluate the Kotlin program?

Are there any tools that can help check some code in Kotlin?

I can use something similar to the approaches suggested here: http://www.ibm.com/developerworks/java/library/j-benchmark1/index.html - but I was wondering if there are any Kotlin native tools, so I don’t have to reinvent the wheel!

+4
source share
3 answers

For benchmarking use JMH . This structure can help you write the most relevant reference and learn a lot about how the JVM works. There is an old project on github , but I hope you can just upgrade versions and well.

+6
source

All low-level performance comparison tools are the same as Java, because the bytecode is identical.

If with Kotlin's own tools you mean syntactic sugar for measuring (relative) performance, then stdlib provides measureTimeMillisand measureNanoTime:

fun main(args: Array<String>) {
    val benchmark = measureNanoTime {
        // some slow code here
    }
}

, .

+3

- : https://gist.github.com/olegcherr/b62a09aba1bff643a049

:

simpleMeasureTest {
  // your code for the benchmark
}

You can also set up testing, for example:

simpleMeasureTest(ITERATIONS = 1000, TEST_COUNT = 10, WARM_COUNT = 2) {
  // your code for the benchmark
}

After running this code, enter the console. The result will look like this:

I/System.out: [TimeTest] -> go
I/System.out: [TimeTest] Warming 1 of 2
I/System.out: [TimeTest] Warming 2 of 2
I/System.out: [TimeTest] 770ms
I/System.out: [TimeTest] 784ms
I/System.out: [TimeTest] 788ms
I/System.out: [TimeTest] 881ms
I/System.out: [TimeTest] 802ms
I/System.out: [TimeTest] 794ms
I/System.out: [TimeTest] 789ms
I/System.out: [TimeTest] 786ms
I/System.out: [TimeTest] 750ms
I/System.out: [TimeTest] 762ms
I/System.out: [TimeTest] -> average=790ms / median=788ms

To make your life easier, create a new console output filter. Here is my filter in Android Studio:

enter image description here

+3
source

All Articles