Repository: JetBrains/kotlin
File: libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/targets/native/performance/KotlinPerformancePlugin.kt (Kotlin)

Code before:
import org.gradle.api.Task
import org.gradle.api.execution.TaskExecutionListener
import org.gradle.api.plugins.ExtraPropertiesExtension
import org.gradle.api.tasks.TaskState
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.addExtension
import org.jetbrains.kotlin.gradle.plugin.mpp.disambiguateName
import org.jetbrains.kotlin.gradle.targets.native.tasks.NativePerformanceReport
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
import java.io.File
import java.util.concurrent.ConcurrentHashMap

class TaskTime(val startTime: Long) {
    var duration: Double? = null
}

class TaskTimerListener(project: Project) : TaskExecutionListener {
    val tasksTimes = getOrRegisterStorage<String, TaskTime>(project, "org.jetbrains.kotlin.native.taskTimes")
    fun getTime(taskName: String) = tasksTimes[taskName]?.duration ?: 0.0

    override fun beforeExecute(task: Task) {
        tasksTimes[task.path] = TaskTime(System.nanoTime())
    }

    override fun afterExecute(task: Task, taskState: TaskState) {
        tasksTimes[task.path]!!.duration = (System.nanoTime() - tasksTimes[task.path]!!.startTime) / 1000.0
    }

    companion object {
        @Suppress("UNCHECKED_CAST")
        private fun <K, V> getOrRegisterStorage(project: Project, propertyName: String): ConcurrentHashMap<K, V> =
            project.rootProject.extensions.getByType(ExtraPropertiesExtension::class.java).run {
                if (!has(propertyName)) {
                    set(propertyName, ConcurrentHashMap<K, V>())
                }
                get(propertyName)
            } as ConcurrentHashMap<K, V>
    }
}

open class KotlinPerformancePlugin : Plugin<Project> {
    private fun checkSettings(project: Project, performanceExtension: PerformanceExtension): Boolean {
        var result = true
        if (performanceExtension.metrics.isEmpty()) {
            project.logger.warn("There is no tracked metrics. Please, provide metrics in settings of $EXTENSION_NAME plugin.")
            result = false
        }
        // Find binaries with trackable performance.
        if (performanceExtension.trackedBinaries.isEmpty()) {
            project.logger.warn("There is no tracked binaries. Please, provide binaries in settings of $EXTENSION_NAME plugin.")
            result = false

Review comment (suggestion):
```suggestion
        val taskTime = taskTimes.getValue(task.path)
        taskTime.duration = (System.nanoTime() - taskTime.startTime) / 1000.0
```

Code after:
import org.gradle.api.Task
import org.gradle.api.execution.TaskExecutionListener
import org.gradle.api.plugins.ExtraPropertiesExtension
import org.gradle.api.tasks.TaskState
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.addExtension
import org.jetbrains.kotlin.gradle.plugin.mpp.disambiguateName
import org.jetbrains.kotlin.gradle.targets.native.tasks.NativePerformanceReport
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
import java.io.File
import java.util.concurrent.ConcurrentHashMap

class TaskTime(val startTime: Long) {
    var duration: Double? = null
}

class TaskTimerListener(project: Project) : TaskExecutionListener {
    val tasksTimes = getOrRegisterStorage<String, TaskTime>(project, "org.jetbrains.kotlin.native.taskTimes")
    fun getTime(taskName: String) = tasksTimes[taskName]?.duration ?: 0.0

    override fun beforeExecute(task: Task) {
        tasksTimes[task.path] = TaskTime(System.nanoTime())
    }

    override fun afterExecute(task: Task, taskState: TaskState) {
        val taskTime = tasksTimes.getValue(task.path)
        taskTime.duration = (System.nanoTime() - taskTime.startTime) / 1000.0
    }

    companion object {
        @Suppress("UNCHECKED_CAST")
        private fun <K, V> getOrRegisterStorage(project: Project, propertyName: String): ConcurrentHashMap<K, V> =
            project.rootProject.extensions.getByType(ExtraPropertiesExtension::class.java).run {
                if (!has(propertyName)) {
                    set(propertyName, ConcurrentHashMap<K, V>())
                }
                get(propertyName)
            } as ConcurrentHashMap<K, V>
    }
}

open class KotlinPerformancePlugin : Plugin<Project> {
    private fun checkSettings(project: Project, performanceExtension: PerformanceExtension): Boolean {
        var result = true
        if (performanceExtension.metrics.isEmpty()) {
            project.logger.warn("There is no tracked metrics. Please, provide metrics in settings of $EXTENSION_NAME plugin.")
            result = false
        }
        // Find binaries with trackable performance.
        if (performanceExtension.trackedBinaries.isEmpty()) {
            project.logger.warn("There is no tracked binaries. Please, provide binaries in settings of $EXTENSION_NAME plugin.")