[racket] Strange time function results

From: Harry Spier (vasishtha.spier at gmail.com)
Date: Wed May 16 16:22:34 EDT 2012

I've just started using the "time" function to check the timings of
some functions in my program.   I'm testing the timings of two
functions, each of these functions takes a list of lists and
transforms it into another list of lists.  The size of each list of
lists is in the order of  about 1000 x 1000.

Each time I used it in DRacket I got very different results.  So I did
this test.
I put three calls to the two functions right after each other in the
program as follows.

. . .
(define page-as-binary-matrix  (time (image-file->binary-matrix
path-to-image-of-page)))
(define black-pixel-matrix (time (create-matrix-of-black-pixel-ranges
page-as-binary-matrix)))

(define page-as-binary-matrix1  (time (image-file->binary-matrix
path-to-image-of-page)))
(define black-pixel-matrix1 (time (create-matrix-of-black-pixel-ranges
page-as-binary-matrix)))

(define page-as-binary-matrix2  (time (image-file->binary-matrix
path-to-image-of-page)))
(define black-pixel-matrix2 (time (create-matrix-of-black-pixel-ranges
page-as-binary-matrix)))


and got these results

cpu time: 7176 real time: 6620 gc time: 4537
cpu time: 2262 real time: 2289 gc time: 437

cpu time: 5600 real time: 5257 gc time: 2949
cpu time: 3728 real time: 3516 gc time: 1748

cpu time: 4040 real time: 3673 gc time: 1388
cpu time: 2418 real time: 2311 gc time: 422

Its in DrRacket on a dual core pentium under windows.

Why the widely divergent timings and why is CPU time in general more
than real-time?

Thanks,
Harry

Posted on the users mailing list.