Call JS function from Kotlin

I’m trying to compile kotlin to js. Code:

import org.w3c.performance.Performance

fun main(args: Array<String>) {
    val start = Performance().now()
    
   // do stuff

    val end = Performance().now()
}

Then /path/to/kotlin/compiler/bin/kotlinc-js ./MyFile.kt -output run.js throws

error: cannot create an instance of an abstract class
    val end = Performance().now()

How to call js implementation of Performace properly?

I have no idea how to resolve this problem but you could use the Kotlin Duration stdlib API!

val (value, duration) = measureTimedValue {
    Thread.sleep(100)
    42
}

I don’t know that API, but it looks like Performance.now() could work.

The Window object has a property performance of type Performance.

According to the documentation of the Performance interface:

An object of this type can be obtained by calling the window.performance read-only attribute.

So your code should look something like this:

import kotlin.browser.window

fun main() {
    val start = window.performance.now()

    // do stuff

    val end = window.performance.now()
}