What is the idiomatic way to get size of a set?
set-count
A question about system time and time-apply. What is CPU time in milliseconds? I didn’t expect it to be greater than “real” time. md5.rkt> (time-apply low-hash '("hello" 6))
'("000000d34f14273a4ac44616daa9b8d1")
15891
15887
126
It seems it takes more CPU time than “real” time. So I must not know what CPU-time in milliseconds is. Indeed, I don’t think I know.
Above, 15891 is CPU time in milliseconds. Then 15887 is real time. And 126 is garbage-collection time.
I don’t know the actual answer but reading the docs for time-apply
would indicate to me that the first value is the total cpu time to run the entire time-apply
procedure and the second is the cpu time that the procedure you are measuring took.
I have a guess, but I don’t know the actual answer either.
CPU time is probably the total time that the Racket process itself executes stuff.
I’m pretty sure real time is the actual running time. This includes the running time from other processes that Racket spawns. On the other hand, if Racket uses parallelism, real time could be less than CPU time.
For example, (time (sleep 2))
outputs cpu time: 375 real time: 2000 gc time: 1
because the actual running time is really 2000ms, but the Racket process doesn’t actively execute anything for the whole 2000ms.
As another example, consider the example from https://docs.racket-lang.org/guide/parallelism.html#%28part._effective-futures%29
#lang racket
(define (any-double? l)
(for/or ([i (in-list l)])
(for/or ([i2 (in-list l)])
(= i2 (* 2 i)))))
(define l1 (for/list ([i (in-range 5000)])
(+ (* 2 i) 1)))
(define l2 (for/list ([i (in-range 5000)])
(- (* 2 i) 1)))
(time (or (any-double? l1)
(any-double? l2)))
This outputs cpu time: 406 real time: 438 gc time: 47
, which is totally reasonable.
But now, run:
(time (let ([f (future (lambda () (any-double? l2)))])
(or (any-double? l1)
(touch f))))
This outputs cpu time: 403 real time: 302 gc time: 41
. You can see that the CPU time of this code and the previous code is similar, because they still have the same workload to compute. What changes is that we now utilize parallelism, so the actual running time is significantly decreased.
If more than one core is active, it seems CPU time could be greater than real time.