0be666cd5a2ba146b8a78c261130c71ec4953751
[bpt/guile.git] / ice-9 / time.scm
1 ;;;; Copyright (C) 2001 Free Software Foundation, Inc.
2 ;;;;
3 ;;;; This program is free software; you can redistribute it and/or modify
4 ;;;; it under the terms of the GNU General Public License as published by
5 ;;;; the Free Software Foundation; either version 2, or (at your option)
6 ;;;; any later version.
7 ;;;;
8 ;;;; This program is distributed in the hope that it will be useful,
9 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 ;;;; GNU General Public License for more details.
12 ;;;;
13 ;;;; You should have received a copy of the GNU General Public License
14 ;;;; along with this software; see the file COPYING. If not, write to
15 ;;;; the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
16 ;;;; Boston, MA 02111-1307 USA
17 ;;;;
18 \f
19
20 (define-module (ice-9 time)
21 :use-module (ice-9 format)
22 :export (time))
23
24 (define-macro (time form)
25 (let* ((gc-start (gc-run-time))
26 (tms-start (times))
27 (result (eval form (interaction-environment)))
28 (tms-end (times))
29 (gc-end (gc-run-time)))
30 (define (get proc start end)
31 (/ (- (proc end) (proc start)) internal-time-units-per-second))
32 (display "clock utime stime cutime cstime gctime\n")
33 (format #t "~5,2F ~5,2F ~5,2F ~6,2F ~6,2F ~6,2F\n"
34 (get tms:clock tms-start tms-end)
35 (get tms:utime tms-start tms-end)
36 (get tms:stime tms-start tms-end)
37 (get tms:cutime tms-start tms-end)
38 (get tms:cstime tms-start tms-end)
39 (get id gc-start gc-end))
40 result))