Skip to content

Instantly share code, notes, and snippets.

@malkia
Created May 26, 2010 04:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save malkia/414081 to your computer and use it in GitHub Desktop.
Save malkia/414081 to your computer and use it in GitHub Desktop.
; 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)
@malkia
Copy link
Author

malkia commented May 26, 2010

Found a bug. I'm over-optimizing, and 1073741824 is bigger than most-positive-fixnum on 32-bit windows which is 536870911

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment