* strings.c (scm_mem2string): use memcpy rather than by-hand loop.
[bpt/guile.git] / ice-9 / time.scm
CommitLineData
5e38caf1 1;;;; Copyright (C) 2001 Free Software Foundation, Inc.
e7d82feb 2;;;;
73be1d9e
MV
3;;;; This library is free software; you can redistribute it and/or
4;;;; modify it under the terms of the GNU Lesser General Public
5;;;; License as published by the Free Software Foundation; either
6;;;; version 2.1 of the License, or (at your option) any later version.
7;;;;
8;;;; This library is distributed in the hope that it will be useful,
5e38caf1 9;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
73be1d9e
MV
10;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11;;;; Lesser General Public License for more details.
12;;;;
13;;;; You should have received a copy of the GNU Lesser General Public
14;;;; License along with this library; if not, write to the Free Software
15;;;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
a482f2cc 16;;;;
5e38caf1 17\f
e7d82feb
TTN
18;;; Commentary:
19
20;; This module exports a single macro: `time'.
21;; Usage: (time exp)
22;;
23;; Example:
24;; guile> (time (sleep 3))
25;; clock utime stime cutime cstime gctime
26;; 3.01 0.00 0.00 0.00 0.00 0.00
27;; 0
28
29;;; Code:
5e38caf1
KN
30
31(define-module (ice-9 time)
32 :use-module (ice-9 format)
33 :export (time))
34
3b9e23a7 35(define (time-proc proc)
5e38caf1 36 (let* ((gc-start (gc-run-time))
3b9e23a7
KN
37 (tms-start (times))
38 (result (proc))
39 (tms-end (times))
40 (gc-end (gc-run-time)))
5e38caf1
KN
41 (define (get proc start end)
42 (/ (- (proc end) (proc start)) internal-time-units-per-second))
43 (display "clock utime stime cutime cstime gctime\n")
44 (format #t "~5,2F ~5,2F ~5,2F ~6,2F ~6,2F ~6,2F\n"
3b9e23a7
KN
45 (get tms:clock tms-start tms-end)
46 (get tms:utime tms-start tms-end)
47 (get tms:stime tms-start tms-end)
48 (get tms:cutime tms-start tms-end)
49 (get tms:cstime tms-start tms-end)
262098e0 50 (get identity gc-start gc-end))
5e38caf1 51 result))
3b9e23a7
KN
52
53(define-macro (time exp)
54 `(,time-proc (lambda () ,exp)))
e7d82feb
TTN
55
56;;; time.scm ends here