(use z3 posix) ;;; comparing performance of z3-compression, versus compression using ;;; an external gzip process. I know this is apples and oranges, but ;;; I'm just confused by the really poor performance of z3. Am I doing ;;; something wrong? (define-macro (repeat-test n . body) (let ((loop (gensym "loop")) (times (gensym "times"))) `(begin (printf "~%Test expression is: ~a~%" ',@body) (printf "Evaluating once. Return value is: ~s~%" ,@body) (printf "Repeating ~a times:~%" ,n) (time (let ,loop ((,times ,n)) (when (positive? ,times) ,@body (,loop (sub1 ,times)))))))) (define (gzip-string s) (receive (in out pid) (process "gzip") (write-string s #f out) (close-output-port out) (let ((result (read-string #f in))) (close-input-port in) result))) (define (z3:compress-string input) (let* ((dest (open-output-string)) (r (lambda (x) (display x dest))) (ze (z3:encode-init))) (let loop ((c input)) (let ((t (z3:encode ze r c))) (when t (loop (substring c t))))) (get-output-string dest))) (define *input* (make-string 1000 #\x)) (repeat-test 1000 (string-length (gzip-string *input*))) (repeat-test 1000 (string-length (z3:compress-string *input*)))