home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume1 / 8707 / 49 / div.cl < prev    next >
Lisp/Scheme  |  1990-07-13  |  1KB  |  52 lines

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ; File:         div.cl
  3. ; Description:  DIV benchmarks
  4. ; Author:       Richard Gabriel
  5. ; Created:      8-Apr-85
  6. ; Modified:     19-Jul-85 18:28:01 (Bob Shaw)
  7. ; Language:     Common Lisp
  8. ; Package:      User
  9. ; Status:       Public Domain
  10. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11.  
  12. ;;; DIV2 -- Benchmark which divides by 2 using lists of n ()'s.
  13. ;;; This file contains a recursive as well as an iterative test.
  14.  
  15. (defun create-n (n)
  16.   (do ((n n (1- n))
  17.        (a () (push () a)))
  18.       ((= n 0) a)
  19.     (declare (fixnum n))))
  20.  
  21. (defvar *ll* (create-n 200))
  22.  
  23. (defun iterative-div2 (l)
  24.   (do ((l l (cddr l))
  25.        (a () (push (car l) a)))
  26.       ((null l) a)))
  27.  
  28. (defun recursive-div2 (l)
  29.   (cond ((null l) ())
  30.     (t (cons (car l) (recursive-div2 (cddr l))))))
  31.  
  32. (defun test-1 (l)
  33.   (do ((i 300 (1- i)))
  34.       ((= i 0))
  35.     (declare (fixnum i))
  36.     (iterative-div2 l)
  37.     (iterative-div2 l)))
  38.  
  39. (defun test-2 (l)
  40.   (do ((i 300 (1- i)))
  41.       ((= i 0))
  42.     (declare (fixnum i))
  43.     (recursive-div2 l)
  44.     (recursive-div2 l)))
  45.  
  46. ;;; for the iterative test call: (test-1 *ll*)
  47. ;;; for the recursive test call: (test-2 *ll*)
  48.  
  49. (run-benchmark "Div-iter" '(test-1 *ll*))
  50. (run-benchmark "Div-rec" '(test-2 *ll*))
  51.  
  52.