You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.6 KiB

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