;;; -*- Mode:LISP; Package:USER; Base:10 -*-


(compiler:define-micro-properties foo (a b)
  :opcode #o1700)

(compiler:define-micro-properties foobar (a b)
  :opcode #o1701)

(compiler:define-micro-properties foo-micro (a b)
  :opcode #o1702)

(compiler:define-micro-properties foo-micro-no-misc (a b))

(compiler:define-micro-properties si:foobaz (a b)
  :opcode #o1300)

(defun footest ()
  (foo 1 (foobar 2 (si:foobaz 3 4))))

(defun foo (a b)
  (+ a b))

(defun foo-micro (a b)
  (the fixnum (+ (the fixnum a) (the fixnum b))))

(defun foo-micro-no-misc (a b)
  (the fixnum (+ (the fixnum a) (the fixnum b))))

(defun foobar (a b)
  (+ a b))

(defun si:foobaz (a b)
  (+ a b))


(defun foo-load (&aux (funs '(foo foobar si:foobaz foo-micro foo-micro-no-misc)))
  (apply 'compiler:ma-load funs)
  (mapcar 'compiler:enable-micro-misc (remq 'foo-micro-no-misc funs))
  (compiler:describe-misc-map))

(defun foo-loop ()
  (without-interrupts
    (let ((time (get-internal-real-time)))
      (dotimes (j 100000.))
      (quotient (- (get-internal-real-time) time)
		(float internal-time-units-per-second)))))

(defun foo-loop-micro ()
  (without-interrupts
    (let ((time (get-internal-real-time)))
      (dotimes (j 100000.)
	(foo-micro 1 1))
      (quotient (- (get-internal-real-time) time)
		(float internal-time-units-per-second)))))

(defun foo-loop-micro-no-misc ()
  (without-interrupts
    (let ((time (get-internal-real-time)))
      (dotimes (j 100000.)
	(foo-micro-no-misc 1 1))
      (quotient (- (get-internal-real-time) time)
		(float internal-time-units-per-second)))))

(defun foo-loop-macro ()
  (without-interrupts
    (let ((time (get-internal-real-time)))
      (dotimes (j 100000.)
	(foo-macro 1 1))
      (quotient (- (get-internal-real-time) time)
		(float internal-time-units-per-second)))))


(defun foo-better-test ()
  ;; returns 2.63
  (quotient (foo-loop-macro) (foo-loop-micro)))

(defun foo-macro (a b)
  (+ a b))

