#!/usr/bin/env -S sbcl --script
(load "~/.sbclrc")
(require :sb-sprof)
(declaim (optimize (speed 3) (safety 0) (debug 0)))
(defun main ()
(declare (optimize (speed 3) (safety 0) (debug 0)))
(let ((i 0)
(line nil))
(declare (fixnum i)
(type (or string null) line))
(loop
do (setf line (read-line *standard-input* nil))
while line
do (incf i)
finally (format t "size: ~a~%" i))))
(eval-when (:execute)
(sb-sprof:with-profiling
(:max-samples 100000
:sample-interval 0.00001
:report :graph)
(main)))
It indeed wastes most of its time with UFT-8 conversion stuff. If I use (with-open-file (str file) :external-format :my-format ...) it goes faster, but then I can't use stdin.