Created
May 26, 2010 04:54
-
-
Save malkia/414081 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Under Lispworks 6.01 32-bit Windows Vista | |
; | |
; CL-USER 100 > (test-fun) | |
; (i & 0x80000000) == 0 time: 0.717 | |
; (i & 0xFFFFFFFF) == 0 time: 0.671 | |
; (i & 0x00000001) == 0 time: 0.718 | |
; (i & 0x00000003) == 0 time: 0.795 | |
; (i & 0x00000002) == 0 time: 0.827 | |
; (i & 0x00000004) == 0 time: 0.78 | |
; (i & 0x00000008) == 0 time: 0.811 | |
; (i & 0x00000010) == 0 time: 0.999 | |
; NIL | |
(declaim (optimize (speed 3) (compilation-speed 0) (safety 0) | |
(space 0) (debug 0) #+lispworks (hcl:fixnum-safety 0))) | |
(defparameter *funcs* nil) | |
(defmacro make-fun (arg) | |
(let ((name (intern (format nil "TEST-~A" arg)))) | |
(pushnew (list arg name) *funcs*) | |
`(defun ,name () | |
(let ((s 0)) | |
(declare (fixnum s)) | |
(dotimes (n 1073741824) | |
(declare (fixnum n)) | |
(when (= 0 (logand n ,arg)) | |
(setf s (the fixnum (+ 1 s))))) | |
s)))) | |
(make-fun #x80000000) | |
(make-fun #xFFFFFFFF) | |
(make-fun #x00000001) | |
(make-fun #x00000003) | |
(make-fun #x00000002) | |
(make-fun #x00000004) | |
(make-fun #x00000008) | |
(make-fun #x00000010) | |
(setf *funcs* (nreverse *funcs*)) | |
(defun time-it (f) | |
(let ((time (get-internal-run-time))) | |
(funcall f) | |
(float (/ (- (get-internal-run-time) time) | |
internal-time-units-per-second)))) | |
(defun test-fun () | |
(dolist (l *funcs*) | |
(format t "(i & 0x~8,'0X) == 0 time: ~A~&" | |
(first l) | |
(time-it (second l))))) | |
#+nil | |
(test-fun) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Found a bug. I'm over-optimizing, and 1073741824 is bigger than most-positive-fixnum on 32-bit windows which is 536870911