peroxide
peroxide copied to clipboard
benchmark
as expected for such a young project, peroxide is really slow, about 150K times slower than petite-chez
benchmark script from reddit
(define (erato n z primes)
(define (sieve s)
(if (or (null? s) ; prime
(< n (* (car s) (car s)))) ; prime!
(erato (+ n 1) z (append primes (list n)))
(if (zero? (modulo n (car s))) ; composite
(erato (+ n 1) z primes)
(sieve (cdr s)))))
(if (< n z)
(sieve primes)
primes))
(define (primes<2n n)
(erato 2 (* n 2) (list)))
; load and time are not implemented in peroxide
(primes<2n 100)
; 25 seconds on peroxide scheme interpreter
; 0.000167 seconds on petite-chez scheme interpreter
; -> peroxide is about 150K times slower than petite-chez
; (load "erato.scm")
; (define a (time (primes<2n 100000)))
; 2.7 seconds on petite-chez scheme interpreter
; 3.2 seconds on racket scheme interpreter
; 6.9 seconds on gambit scheme interpreter
; 48.3 seconds on chicken scheme interpreter
Strange - (primes<2n 100) ran almost instantly on my system (AMD FX-8320E, CPU max MHz 3200.0000)
Yeah, I finally ran this and it does run almost instantly for me too, both in debug and release mode (on an old Macbook).
Interestingly (primes<2n 100000) fails when it reaches maximum recursion depth in append, which is slow and not tail-recursive... I'll look into that
seems an issue with garbage collection
Strange -
(primes<2n 100)ran almost instantly on my system
same, when i run only (primes<2n 100) in a "fresh" peroxide interpreter (no history)
(primes<2n 1000) takes about 3 seconds on my old 2x2.4GHz cpu, 2GB free ram
second run: also 3 seconds
third run: hangs forever
Ah, thanks for the explanation! I can reproduce that.
Definitely a GC problem: if I turn the GC off using --gc-mode off, the run time doesn't increase on subsequent runs.
A few updates:
- I've added a
timemacro which returns the number of seconds it takes to execute its argument - I've fixed
appendso it runs with constant memory use - I've tweaked the GC a bit, and fixed a couple obvious performance issues.
(primes<2n 100000) now runs successfully, although it takes almost 8 minutes on my machine.
yay : )
;; all primes < 10^3 < 10^4 < 10^5 < 10^6
;; interpreter
;; petite (chez scheme) 8.4 0 sec 0 sec 2 sec 2 min
;; PLT-r5rs (racket) 5.3.6 0 sec 0 sec 2 sec 4 min
;; pi (rhizome/pi) 0.57 0 sec 0 sec 2 sec 6 min
;; gsi (gambit) 4.7.0 0 sec 0 sec 4 sec 13 min
;; csi (chicken) 4.8.0.5 0 sec 0 sec 10 sec 18 min
;; scheme 48 1.9 0 sec 0 sec 10 sec n/a
;; peroxide 480 sec
about 150K times slower than petite-chez
so now peroxide is only 240 times slower than petite-chez ; )