I'm really glad you responded -- I wasn't aware gambit-list blocked attachments<br><br><br><br><br>$ cat bench.scm:<br>(define (gen-lst min max)<br> (define (helper min max cur)<br> (if (< min max)<br> (helper min (- max 1) (cons max cur))<br>
cur))<br> (helper (- min 1) (- max 1) '()))<br><br>(define (pad-with value amount lst)<br> (define (helper amount lst)<br> (if (<= amount 0) lst<br> (helper (- amount 1) (cons value lst))))<br> (helper amount lst))<br>
<br>(define (pad-to value ttl-length lst)<br> (pad-with value (- ttl-length (length lst)) lst))<br><br>(define (convert-to-base value base)<br> (define (helper value cur)<br> (if (= value 0) cur<br> (helper (quotient value base) (cons (remainder value base) cur))))<br>
(helper value '()))<br><br>(define (base-to-int lst base)<br> (define (helper lst cur)<br> (if (null? lst) cur<br> (helper (cdr lst) (+ (* cur base) (car lst)))))<br> (helper lst 0))<br><br>(define (int-as-length8-uvector value)<br>
(list->u8vector (pad-to 0 8 (convert-to-base value 256))))<br><br>(define (length8-uvector-as-int vec)<br> (base-to-int (u8vector->list vec) 256))<br><br><br>;(pp (base-to-int (convert-to-base 123456 10) 10))<br>
<br>;(pp (list->u8vector '(1 2 3 4 5 255)))<br><br>(define (make-timer)<br> (let ((start-time 0))<br> (define (dispatch cmd)<br> (cond ((equal? cmd 'start)<br> (set! start-time (time->seconds (current-time))))<br>
((equal? cmd 'stop)<br> (- (time->seconds (current-time)) start-time))))<br> dispatch))<br><br>(define my-timer (make-timer))<br> <br> ;(pp (gen-lst 0 10))<br>
<br>(define (serialize-text object filename)<br> (call-with-output-file filename<br> (lambda (file)<br> (pp object file))))<br><br>(define (serialize-binary object filename)<br> (call-with-output-file filename<br>
(lambda (file)<br> (let ((as-vec (object->u8vector object)))<br> (write-subu8vector (int-as-length8-uvector (u8vector-length as-vec)) 0 8 file)<br> (write-subu8vector as-vec 0 (u8vector-length as-vec) file)))))<br>
<br>(define (unserialize-binary filename)<br> (call-with-input-file filename<br> (lambda (file)<br> (let* ((vec (make-u8vector 8)))<br> (read-subu8vector vec 0 8 file)<br> (let* ((len (length8-uvector-as-int vec))<br>
(obj-vec (make-u8vector len)))<br> (read-subu8vector obj-vec 0 len file)<br> (u8vector->object obj-vec))))))<br><br><br><br><br>(define (bench number-of-entries)<br> <br> (define object (gen-lst 0 number-of-entries))<br>
<br> (serialize-text object "plain_text")<br> (serialize-binary object "binary")<br><br> (let ((plain-time 0)<br> (binary-time 0))<br><br><br> (my-timer 'start)<br> (unserialize-binary "binary")<br>
(set! binary-time (my-timer 'stop))<br><br> (my-timer 'start)<br> (read-all (open-input-file "plain_text"))<br> (set! plain-time (my-timer 'stop))<br><br> (pp `(number-of-entries: ,number-of-entries (binary: ,binary-time) (plain: ,plain-time)))))<br>
<br> <br>(bench 1)<br>(bench 10)<br>(bench 100)<br>(bench 1000)<br>(bench 10000)<br>(bench 100000)<br>(bench 1000000)<br>(bench 10000000)<br><br><br><br>$ gsi bench.scm<br>(number-of-entries: 1 (binary: 5.1021575927734375e-5) (plain: 3.0040740966796875e-5))<br>
(number-of-entries: 10 (binary: 3.0040740966796875e-5) (plain: 2.4080276489257812e-5))<br>(number-of-entries: 100 (binary: 4.792213439941406e-5) (plain: 5.698204040527344e-5))<br>(number-of-entries: 1000 (binary: 2.8395652770996094e-4) (plain: 4.1794776916503906e-4))<br>
(number-of-entries: 10000 (binary: .004720926284790039) (plain: .009029150009155273))<br>(number-of-entries: 100000 (binary: .07220315933227539) (plain: .052423954010009766))<br>(number-of-entries: 1000000 (binary: 1.0091660022735596) (plain: .6231379508972168))<br>
(number-of-entries: 10000000 (binary: 9.397350072860718) (plain: 17.698192834854126))<br><br><br><br><div class="gmail_quote">On Mon, Feb 16, 2009 at 6:22 PM, Adrien Piérard <span dir="ltr"><<a href="mailto:pierarda@iro.umontreal.ca">pierarda@iro.umontreal.ca</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="Ih2E3d"><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
For most of them, plain_text appears to be faster; and only at 10 million entries, does the binary format become slightly faster. What am I doing wrong?<br>
</blockquote></div><br></div>You are not showing us the code. That is just *wrong*.<br><br>Are you converting each number independently, or the whole list at once?<br>
<br>
P!<br clear="all"><font color="#888888"><br>-- <br>Français, English, 日本語, 한국어<br><br>
</font></blockquote></div><br>