Calculating My Average Post Size

Most of my posts are pretty short: maybe 250 words or so. The other day, I began to wonder how long the average post is so I wrote a few lines of Elisp code and just executed it in the scratch buffer.

Here's the code:

(let ((posts 0) (words 0))
  (mapc (lambda(p)
          (with-temp-buffer
            (insert-file-contents p)
            (goto-char 1)
            (setq words (+ words (how-many "\\w+")))
            (setq posts (1+ posts))))
        (directory-files "~/org/blog" t ".*\\.org"))
  (format "Total words: %s, Average per Post: %s" words (/ words posts)))

As you can see there's nothing special in it. The only points worthy of note are the use of with-temp-buffer and =insert-file-contents instead of find-file, a trick I learned from Xah Lee, and the use of directory-files, which is a nice way of getting a list of files satisfying some regex.

When I run the code I get

Total words: 362460, Average per Post: 303

so my posts are a bit longer than I thought. It's also interesting that in the 3 years I've been posting to Irreal, I've written about 360,000 words or 120,000 words a year. That's about a novel's worth of words a year. Now if I could only write a novel.

This entry was posted in Programming and tagged . Bookmark the permalink.