;; Return the contents of FILE as a string... extremely slowly. (defun BcmFileSlurpSlowly (file "t") (let (port line (lines "")) (unless (setq port (infile file)) (error "Can't open %s" file)) (while (gets line port) (setq lines (strcat lines line))) (close port) lines)) ;; Return the contents of FILE as a string less slowly. (defun BcmFileSlurpQuick (file "t") (let (port line lines) (unless (setq port (infile file)) (error "Can't open %s" file)) (while (gets line port) (push line lines)) (close port) (buildString (reverse lines) "")))> (sh "ypcat passwd > /tmp/passwd")> (sh "wc -l /tmp/passwd") 39076 /tmp/passwd t> measureTime (BcmFileSlurpSlowly "/tmp/passwd") (207.8354 1.708741 209.6785 0) Three and a half minutes for a 39 kiloLine file?! :O > measureTime (BcmFileSlurpQuick "/tmp/passwd") (0.06999 0.001 0.07150483 0) That's better. :)
Questions:
- Why is strcat so much slower than push + buildString + reverse?
- Why doesn't allocate('string 39076) help make the strcat() method faster?
- Could this be done even more quickly than BcmFileSlurpQuick()? What is the fastest known way to slurp a file in SKILL?