]> www.ginac.de Git - cln.git/blob - benchmarks/timebench2a.lisp
* cln.pc.in: Fix typo.
[cln.git] / benchmarks / timebench2a.lisp
1 (defvar x1)
2 (defvar x2)
3 (defvar x3)
4 (defvar y)
5 (defvar z)
6
7 (defun elementary-benchmark (N repeat)
8   (setq x1 (floor (+ (isqrt (* 5 (expt 10 (* 4 N)))) (expt 10 (* 2 N))) 2))
9   (setq x2 (isqrt (* 3 (expt 10 (* 2 N)))))
10   (setq x3 (+ (expt 10 N) 1))
11   (format t "~&~%N = ~D, Multiplication x1*x2, divide times by ~D~%" N repeat)
12   (dotimes (count 3)
13     (time
14       (dotimes (_ repeat)
15         (setq y (* x1 x2)))))
16   (format t "~&~%N = ~D, Division (with remainder) x1 / x2, divide times by ~D~%" N repeat)
17   (dotimes (count 3)
18     (time
19       (dotimes (_ repeat)
20         (multiple-value-setq (y z) (floor x1 x2)))))
21   (format t "~&~%N = ~D, integer_sqrt(x3), divide times by ~D~%" N repeat)
22   (dotimes (count 3)
23     (time
24       (dotimes (_ repeat)
25         (setq y (isqrt x3)))))
26   (format t "~&~%N = ~D, gcd(x1,x2), divide times by ~D~%" N repeat)
27   (dotimes (count 3)
28     (time
29       (dotimes (_ repeat)
30         (setq y (gcd x1 x2)))))
31 )
32
33 (defun pari-benchmark (N repeat)
34   (format t "~&~%N = ~D, pari-benchmark, divide times by ~D~%" N repeat)
35   (dotimes (count 3)
36     (time
37       (dotimes (_ repeat)
38         (let ((u 1) (v 1) (p 1) (q 1))
39           (do ((k 1 (1+ k)))
40               ((> k N) (setq y p z q))
41             (let ((w (+ u v)))
42               (shiftf u v w)
43               (setq p (* p w))
44               (setq q (lcm q w)))))))))
45
46 (defun integer-benchmark ()
47   (elementary-benchmark 100 10000)
48   (elementary-benchmark 1000 1000)
49   (elementary-benchmark 10000 10)
50   (elementary-benchmark 100000 1)
51   (pari-benchmark 100 100)
52   (pari-benchmark 200 10)
53   (pari-benchmark 1000 1)
54 )