-
-
Save priyadarshan/4209e505b3446933d538 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
| (defmacro execution-time (&body body) | |
| "Return the number of milliseconds it takes to execute `body`. Also | |
| returns the result as the second value." | |
| (let ((tm (gensym)) | |
| (res (gensym))) | |
| `(let* ((,tm (get-internal-real-time)) | |
| (,res (progn ,@body)) | |
| (,tm (floor (* 1000 (- (get-internal-real-time) ,tm)) | |
| internal-time-units-per-second))) | |
| (values (float ,tm) ,res)))) | |
| (defmacro aif (test then &optional else) | |
| `(let ((it ,test)) | |
| (if it | |
| ,then | |
| ,else))) | |
| (defun test-a () | |
| (aif (random 100) | |
| 'true | |
| 'false)) | |
| (defun test () | |
| (if (random 100) | |
| 'true | |
| 'false)) | |
| (let ((anaphoric (/ (loop repeat 5 sum (execution-time (loop repeat 10000000 do (test-a)))) 5)) | |
| (not-anaphoric (/ (loop repeat 5 sum (execution-time (loop repeat 10000000 do (test)))) 5))) | |
| (format t "~&Anaphoric: ~A msec / Not-Anaphoric: ~A msec~%It's ~A % slower." | |
| anaphoric | |
| not-anaphoric | |
| (* (/ (- anaphoric not-anaphoric) not-anaphoric) 100))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment