The history of this repo demonstrates how to take a slow xxd implementation in Go, and make it faster than the native version on OSX/Linux.
MIT License
This repository contains my answer to How can I improve the performance of my xxd port? on reddit.
The result is a Go version of xxd that outperforms the native versions on OSX 10.10.1 / Ubuntu 14.04 (inside VirtualBox), see benchmarks below. However, that is not impressive, given that none of the usual xxd flags are supported.
What is interesting however, are the steps to get there:
You can also follow along by looking at the commit history: https://github.com/felixge/go-xxd/commits/master
$ time xxd image.jpg > /dev/null
real 0m0.205s
user 0m0.202s
sys 0m0.003s
$ go build xxd.go && time ./xxd image.jpg > /dev/null
real 0m5.914s
user 0m3.598s
sys 0m2.318s
$ go build xxd.go && time ./xxd image.jpg > /dev/null
real 0m0.138s
user 0m0.133s
sys 0m0.004s
$ time xxd image.jpg > /dev/null
real 0m0.273s
user 0m0.017s
sys 0m0.231s
$ go build xxd.go && time ./xxd image.jpg > /dev/null
real 0m5.856s
user 0m3.517s
sys 0m1.897s
$ go build xxd.go && time ./xxd image.jpg > /dev/null
real 0m0.233s
user 0m0.021s
sys 0m0.207s