src/Pure/General/time.scala
author wenzelm
Tue Nov 29 21:50:00 2011 +0100 (2011-11-29)
changeset 45674 eb65c9d17e2f
parent 45673 src/Pure/General/timing.scala@cd41e3903fbf
child 46712 8650d9a95736
permissions -rw-r--r--
clarified Time vs. Timing;
wenzelm@45674
     1
/*  Title:      Pure/General/time.scala
wenzelm@45673
     2
    Module:     PIDE
wenzelm@40393
     3
    Author:     Makarius
wenzelm@40393
     4
wenzelm@45674
     5
Time based on milliseconds.
wenzelm@40393
     6
*/
wenzelm@40393
     7
wenzelm@40393
     8
package isabelle
wenzelm@40393
     9
wenzelm@45664
    10
wenzelm@40848
    11
object Time
wenzelm@40393
    12
{
wenzelm@40848
    13
  def seconds(s: Double): Time = new Time((s * 1000.0) round)
wenzelm@44699
    14
  def ms(m: Long): Time = new Time(m)
wenzelm@40393
    15
}
wenzelm@40393
    16
wenzelm@45249
    17
class Time private(val ms: Long)
wenzelm@40848
    18
{
wenzelm@40848
    19
  def seconds: Double = ms / 1000.0
wenzelm@40852
    20
wenzelm@40852
    21
  def min(t: Time): Time = if (ms < t.ms) this else t
wenzelm@40852
    22
  def max(t: Time): Time = if (ms > t.ms) this else t
wenzelm@40852
    23
wenzelm@40848
    24
  override def toString =
wenzelm@40848
    25
    String.format(java.util.Locale.ROOT, "%.3f", seconds.asInstanceOf[AnyRef])
wenzelm@40848
    26
  def message: String = toString + "s"
wenzelm@40848
    27
}
wenzelm@40848
    28