Open kstrasser opened 13 years ago
The serializer must avoid using lists at all costs because they are about 7x more expensive time-wise to `write' and produce lots of extra garbage.
Test example: $ ./write.rkt "List trial: " cpu time: 1344 real time: 1345 gc time: 524 "Vector trial: " cpu time: 204 real time: 204 gc time: 0
(require racket/list racket/vector) (print-graph #f)
(define l (make-list 1000000 1)) (define v (make-vector 1000000 1)) (define ol (open-output-bytes)) (define ov (open-output-bytes))
(collect-garbage) (collect-garbage) (collect-garbage) (collect-garbage)
"List trial: " (define wl (time (write l ol) (get-output-bytes ol)))
"Vector trial: " (define wv (time (write v ov) (get-output-bytes ov)))
The serializer must avoid using lists at all costs because they are about 7x more expensive time-wise to `write' and produce lots of extra garbage.
Test example: $ ./write.rkt "List trial: " cpu time: 1344 real time: 1345 gc time: 524 "Vector trial: " cpu time: 204 real time: 204 gc time: 0
! /usr/bin/env racket
lang racket/base
(require racket/list racket/vector) (print-graph #f)
(define l (make-list 1000000 1)) (define v (make-vector 1000000 1)) (define ol (open-output-bytes)) (define ov (open-output-bytes))
(collect-garbage) (collect-garbage) (collect-garbage) (collect-garbage)
"List trial: " (define wl (time (write l ol) (get-output-bytes ol)))
(collect-garbage) (collect-garbage) (collect-garbage) (collect-garbage)
"Vector trial: " (define wv (time (write v ov) (get-output-bytes ov)))