sed versus Perl substitution performance

Software

Rubenerd is now generated with Hugo. The performance difference over Jekyll is stunning, though it does take more post-processing to get things the way I want. One task is replacing certain blocks of exported text from each post.

This is the sed command run over all 4000+ posts:

sed -i '' -e 's/something/else/g' ${post}

Note the empty string. BSD userland sed (FreeBSD, OS X, etc) requires this for inline replace. GNU sed in your Linux of choice does not.

Using time, I consistently get these numbers:

real	0m18.889s
user	0m8.388s
sys	0m10.470s

Not the end of the world, but still significant considering Hugo generates the entire site in only roughly double this time. So what could we do to improve this?

It's still my favourite language, so I tried a Perl substitution:

perl -pe "s/something/else/g $POST > ./TEMP

Perhaps unsurprisingly, a dynamic language writing to a temporary file didn't improve things:

real	0m47.647s
user	0m19.730s
sys	0m20.112s

Needless to say, I'm seriously considering learning Go as my next hobby project.

Author bio and support

Me!

Ruben Schade is a technical writer and IaaS engineer in Sydney, Australia who refers to himself in the third person in bios. Wait, not BIOS… my brain should be EFI by now.

The site is powered by Hugo, FreeBSD, and OpenZFS on OrionVM, everyone’s favourite cloud infrastructure provider.

If you found this post helpful or entertaining, you can shout me a coffee or buy some silly merch. Thanks!