Created
May 16, 2012 03:49
-
-
Save sshirokov/2707215 to your computer and use it in GitHub Desktop.
Comparison of currying vs pushing and reversing a list
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
| (ql:quickload :alexandria) | |
| (use-package :alexandria) | |
| (defmacro rand-char () | |
| '(code-char (+ (random (- (char-code #\z) (char-code #\a))) (char-code #\a)))) | |
| (defun 8k-with-concatenate () | |
| (let ((s (string ""))) | |
| (dotimes (i (* 1024 8)) | |
| (setf s (concatenate 'string s (list (rand-char))))) | |
| s)) | |
| (defun 8k-with-push () | |
| (let ((l (list))) | |
| (dotimes (i (* 1024 8)) | |
| (push (rand-char) l)) | |
| (coerce (reverse l) 'string))) | |
| (defun 8k-with-curry () | |
| (let ((fl (curry #'list))) | |
| (dotimes (i (* 1024 8)) | |
| (setf fl (curry fl (rand-char)))) | |
| (coerce (funcall fl) 'string))) | |
| ;; Testing | |
| ;; | |
| ;; CL-USER> (time (length (8k-with-curry))) | |
| ;; Evaluation took: | |
| ;; 0.075 seconds of real time | |
| ;; 0.072005 seconds of total run time (0.068004 user, 0.004001 system) | |
| ;; 96.00% CPU | |
| ;; 227,898,585 processor cycles | |
| ;; 396,960 bytes consed | |
| ;; | |
| ;; 8192 | |
| ;; CL-USER> (time (length (8k-with-push))) | |
| ;; Evaluation took: | |
| ;; 0.000 seconds of real time | |
| ;; 0.000000 seconds of total run time (0.000000 user, 0.000000 system) | |
| ;; 100.00% CPU | |
| ;; 1,349,085 processor cycles | |
| ;; 285,328 bytes consed | |
| ;; | |
| ;; 8192 | |
| ;; CL-USER> (time (length (8k-with-concatenate))) | |
| ;; Evaluation took: | |
| ;; 0.107 seconds of real time | |
| ;; 0.100006 seconds of total run time (0.092006 user, 0.008000 system) | |
| ;; [ Run times consist of 0.008 seconds GC time, and 0.093 seconds non-GC time. ] | |
| ;; 93.46% CPU | |
| ;; 327,936,923 processor cycles | |
| ;; 135,174,848 bytes consed | |
| ;; 8192 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment