From c9868f7f2136011fb64e3f7b86566e6c341b05ed Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 2 Aug 2004 17:41:59 +0000 Subject: [PATCH] Same benchmarks in Common Lisp. Posted in comp.lang.lisp on 2001-09-19. http://groups.google.de/groups?q=%2B%22bignum+operations%22+%2Bhaible&hl=de&lr=&ie=UTF-8&selm=rok7yuj3vu.fsf%40honolulu.ilog.fr&rnum=1 --- benchmarks/timebench2a.lisp | 54 +++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 benchmarks/timebench2a.lisp diff --git a/benchmarks/timebench2a.lisp b/benchmarks/timebench2a.lisp new file mode 100644 index 0000000..eb41be4 --- /dev/null +++ b/benchmarks/timebench2a.lisp @@ -0,0 +1,54 @@ +(defvar x1) +(defvar x2) +(defvar x3) +(defvar y) +(defvar z) + +(defun elementary-benchmark (N repeat) + (setq x1 (floor (+ (isqrt (* 5 (expt 10 (* 4 N)))) (expt 10 (* 2 N))) 2)) + (setq x2 (isqrt (* 3 (expt 10 (* 2 N))))) + (setq x3 (+ (expt 10 N) 1)) + (format t "~&~%N = ~D, Multiplication x1*x2, divide times by ~D~%" N repeat) + (dotimes (count 3) + (time + (dotimes (_ repeat) + (setq y (* x1 x2))))) + (format t "~&~%N = ~D, Division (with remainder) x1 / x2, divide times by ~D~%" N repeat) + (dotimes (count 3) + (time + (dotimes (_ repeat) + (multiple-value-setq (y z) (floor x1 x2))))) + (format t "~&~%N = ~D, integer_sqrt(x3), divide times by ~D~%" N repeat) + (dotimes (count 3) + (time + (dotimes (_ repeat) + (setq y (isqrt x3))))) + (format t "~&~%N = ~D, gcd(x1,x2), divide times by ~D~%" N repeat) + (dotimes (count 3) + (time + (dotimes (_ repeat) + (setq y (gcd x1 x2))))) +) + +(defun pari-benchmark (N repeat) + (format t "~&~%N = ~D, pari-benchmark, divide times by ~D~%" N repeat) + (dotimes (count 3) + (time + (dotimes (_ repeat) + (let ((u 1) (v 1) (p 1) (q 1)) + (do ((k 1 (1+ k))) + ((> k N) (setq y p z q)) + (let ((w (+ u v))) + (shiftf u v w) + (setq p (* p w)) + (setq q (lcm q w))))))))) + +(defun integer-benchmark () + (elementary-benchmark 100 10000) + (elementary-benchmark 1000 1000) + (elementary-benchmark 10000 10) + (elementary-benchmark 100000 1) + (pari-benchmark 100 100) + (pari-benchmark 200 10) + (pari-benchmark 1000 1) +) -- 2.45.0