All Downloads are FREE. Search and download functionalities are using the official Maven repository.

scala.tools.partest.nest.Stopwatch.scala Maven / Gradle / Ivy

There is a newer version: 2.13.15
Show newest version
/*
 * Scala (https://www.scala-lang.org)
 *
 * Copyright EPFL and Lightbend, Inc.
 *
 * Licensed under Apache License 2.0
 * (http://www.apache.org/licenses/LICENSE-2.0).
 *
 * See the NOTICE file distributed with this work for
 * additional information regarding copyright ownership.
 */

package scala.tools.partest.nest

/**
  * Measured elapsed time between between calls to `start` and `stop`.
  * May be `pause`-ed and re-`started` before `stop` is eventually called.
  */
final class Stopwatch {
  private var base: Option[Long] = None
  private var elapsed = 0L
  def pause(): Unit = {
    assert(base.isDefined)
    val now = System.nanoTime
    elapsed += (now - base.get)
    base = None
  }
  def start(): Unit = {
    base = Some(System.nanoTime())
  }

  def stop(): Long = {
    pause()
    (1.0 * elapsed / 1000 / 1000).toLong
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy