Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

benchmark #6

Open
milahu opened this issue Nov 26, 2021 · 6 comments
Open

benchmark #6

milahu opened this issue Nov 26, 2021 · 6 comments

Comments

@milahu
Copy link

milahu commented Nov 26, 2021

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
@jpellegrini
Copy link
Contributor

Strange - (primes<2n 100) ran almost instantly on my system (AMD FX-8320E, CPU max MHz 3200.0000)

@MattX
Copy link
Owner

MattX commented Dec 6, 2021

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

@milahu
Copy link
Author

milahu commented Dec 6, 2021

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

@MattX
Copy link
Owner

MattX commented Dec 6, 2021

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.

@MattX
Copy link
Owner

MattX commented Dec 7, 2021

A few updates:

  • I've added a time macro which returns the number of seconds it takes to execute its argument
  • I've fixed append so 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.

@milahu
Copy link
Author

milahu commented Dec 7, 2021

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 ; )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants