src/Pure/ML-Systems/cpu-timer-basis.ML
author wenzelm
Sat, 11 Jun 2005 23:17:28 +0200
changeset 16374 f4b7cf8975af
parent 14979 245955f0c579
permissions -rw-r--r--
some cygwin support;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14519
4ca3608fdf4f Added support for the newer versions of SML/NJ, which break several of the
skalberg
parents:
diff changeset
     1
(*  Title:      Pure/ML-Systems/cpu-timer-basis.ML
4ca3608fdf4f Added support for the newer versions of SML/NJ, which break several of the
skalberg
parents:
diff changeset
     2
    ID:         $Id$
4ca3608fdf4f Added support for the newer versions of SML/NJ, which break several of the
skalberg
parents:
diff changeset
     3
    Author:     Sebastian Skalberg (TU Muenchen)
4ca3608fdf4f Added support for the newer versions of SML/NJ, which break several of the
skalberg
parents:
diff changeset
     4
4ca3608fdf4f Added support for the newer versions of SML/NJ, which break several of the
skalberg
parents:
diff changeset
     5
Implementation of timing functions, building on standard ("basis library") functions.
4ca3608fdf4f Added support for the newer versions of SML/NJ, which break several of the
skalberg
parents:
diff changeset
     6
*)
4ca3608fdf4f Added support for the newer versions of SML/NJ, which break several of the
skalberg
parents:
diff changeset
     7
4ca3608fdf4f Added support for the newer versions of SML/NJ, which break several of the
skalberg
parents:
diff changeset
     8
(*Note start point for timing*)
4ca3608fdf4f Added support for the newer versions of SML/NJ, which break several of the
skalberg
parents:
diff changeset
     9
fun startTiming() =
4ca3608fdf4f Added support for the newer versions of SML/NJ, which break several of the
skalberg
parents:
diff changeset
    10
  let val CPUtimer = Timer.startCPUTimer();
4ca3608fdf4f Added support for the newer versions of SML/NJ, which break several of the
skalberg
parents:
diff changeset
    11
      val time = Timer.checkCPUTimer(CPUtimer)
4ca3608fdf4f Added support for the newer versions of SML/NJ, which break several of the
skalberg
parents:
diff changeset
    12
  in  (CPUtimer,time)  end;
4ca3608fdf4f Added support for the newer versions of SML/NJ, which break several of the
skalberg
parents:
diff changeset
    13
4ca3608fdf4f Added support for the newer versions of SML/NJ, which break several of the
skalberg
parents:
diff changeset
    14
(*Finish timing and return string*)
4ca3608fdf4f Added support for the newer versions of SML/NJ, which break several of the
skalberg
parents:
diff changeset
    15
fun endTiming (CPUtimer, {sys,usr}) =
4ca3608fdf4f Added support for the newer versions of SML/NJ, which break several of the
skalberg
parents:
diff changeset
    16
  let open Time  (*...for Time.toString, Time.+ and Time.- *)
4ca3608fdf4f Added support for the newer versions of SML/NJ, which break several of the
skalberg
parents:
diff changeset
    17
      val {sys=sys2,usr=usr2} = Timer.checkCPUTimer(CPUtimer)
4ca3608fdf4f Added support for the newer versions of SML/NJ, which break several of the
skalberg
parents:
diff changeset
    18
  in  "User " ^ toString (usr2-usr) ^
4ca3608fdf4f Added support for the newer versions of SML/NJ, which break several of the
skalberg
parents:
diff changeset
    19
      "  All "^ toString (sys2-sys + usr2-usr) ^
4ca3608fdf4f Added support for the newer versions of SML/NJ, which break several of the
skalberg
parents:
diff changeset
    20
      " secs"
4ca3608fdf4f Added support for the newer versions of SML/NJ, which break several of the
skalberg
parents:
diff changeset
    21
      handle Time => ""
4ca3608fdf4f Added support for the newer versions of SML/NJ, which break several of the
skalberg
parents:
diff changeset
    22
  end;
4ca3608fdf4f Added support for the newer versions of SML/NJ, which break several of the
skalberg
parents:
diff changeset
    23
14979
245955f0c579 added checkTimer;
wenzelm
parents: 14519
diff changeset
    24
fun checkTimer timer =
245955f0c579 added checkTimer;
wenzelm
parents: 14519
diff changeset
    25
  let
245955f0c579 added checkTimer;
wenzelm
parents: 14519
diff changeset
    26
    val {sys, usr} = Timer.checkCPUTimer timer;
245955f0c579 added checkTimer;
wenzelm
parents: 14519
diff changeset
    27
    val gc = Timer.checkGCTime timer;    (* FIXME already included in usr? *)
245955f0c579 added checkTimer;
wenzelm
parents: 14519
diff changeset
    28
  in (sys, usr, gc) end;