Last active
June 16, 2019 11:48
-
-
Save inconvergent/2ad3233b710f97cf040d5532d048e832 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
; for every line produced as in run-buffer in | |
; https://bitbucket.org/vityok/cl-faster-input/src/default/src/benchmark-read-line.lisp | |
; do this: | |
(defun proc-line (l) | |
(with-input-from-string (in l) | |
(let ((vals (loop for x = (read in nil nil) while x | |
collect (coerce x 'double-float)))) | |
(values (vec:3vec* (subseq vals 0 3)) | |
(apply #'pigment:rgb (append (mapcar (lambda (v) (/ v 255d0)) | |
(subseq vals 4)) (list 0.3d0))))))) | |
; about twice as fast as my initial approach | |
; current run-buffer looks like this: | |
(defun run-buffer (fn fx &key (buffer-width 80)) | |
(let ((buffer (make-array buffer-width | |
:element-type 'character | |
:initial-element #\space)) | |
(lines 0)) | |
(with-open-file (is fn :direction :input) | |
(loop for (val pos newl) = | |
(multiple-value-list (read-line-into-sequence buffer is | |
:eof-error-p nil)) | |
while val | |
do ; subseq here is probably a bad idea because it reallocates a string? | |
(when newl (funcall fx (subseq val 0 pos))) | |
(incf lines))))) |
lispm
commented
Jun 16, 2019
or even
(defun proc-line (l)
(multiple-value-bind (l0 l1)
(with-input-from-string (in l)
(let ((*read-default-float-format* 'double-float))
(loop for x = (read in nil nil)
for i from 0
while x
if (< i 3)
collect x into l0
else collect (/ x 255d0) into l1
finally (return (values l0 l1)))))
(values (vec:3vec* l0)
(apply #'pigment:rgb (nconc l1 (list 0.3d0))))))
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment