Debian Codegraph @

%3a19/time/compat.mzscheme.sls

raw
1 #!r6rs
2 ;; Copyright 2010 Derick Eddington. My MIT-style license is in the file named
3 ;; LICENSE from the original collection this file is distributed with.
4
5 (library (srfi :19 time compat)
6 (export
7 time-resolution
8 timezone-offset
9 current-time
10 cumulative-thread-time
11 cumulative-process-time
12 cumulative-gc-time
13 time-nanosecond
14 time-second)
15 (import
16 (rnrs base)
17 (only (scheme base)
18 current-seconds
19 seconds->date
20 date-time-zone-offset
21 current-inexact-milliseconds
22 current-thread
23 current-process-milliseconds
24 current-gc-milliseconds))
25
26 ;; MzScheme uses milliseconds, so our resolution in nanoseconds is #e1e6
27 (define time-resolution #e1e6)
28
29 (define timezone-offset
30 (date-time-zone-offset (seconds->date (current-seconds))))
31
32 (define (millis->repr x)
33 (let-values (((d m) (div-and-mod x 1000)))
34 (cons d (* m #e1e6))))
35
36 (define (current-time)
37 (millis->repr (exact (floor (current-inexact-milliseconds)))))
38
39 (define (cumulative-thread-time)
40 (millis->repr (current-process-milliseconds (current-thread))))
41
42 (define (cumulative-process-time)
43 (millis->repr (current-process-milliseconds #F)))
44
45 (define (cumulative-gc-time)
46 (millis->repr (current-gc-milliseconds)))
47
48 (define time-nanosecond cdr)
49 (define time-second car)
50 )