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.
Go Shell
Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is 24 commits ahead, 4 commits behind felixge:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.travis.yml
README.md
go-xxd
image.jpg
install
xxd.go
xxd_test.go

README.md

go-xxd

Build Status Coverage Status

go-xxd is a Go port of the popular xxd and hexdump programs. It reads small files with comparable speed as the native utilities, and reads large files up to twice as fast.

Additionally, this implementation adds some extra flags such as optional bars before/after ASCII output, reverting from C #include/postscript/binary format, and a "smart" seek implementation (using byte unit postfixes like MB, kB, etc.)

For easy installation: curl https://raw.githubusercontent.com/EricLagerg/go-xxd/master/install | bash

Usage:
       xxd [options] [infile [outfile]]
    or
       xxd -r [-s offset] [-c cols] [--ps] [infile [outfile]]
Options:
    -a, --autoskip     toggle autoskip: A single '*' replaces nul-lines. Default off.
    -B, --bars         print pipes/bars before/after ASCII/EBCDIC output. Default off.
    -b, --binary       binary digit dump (incompatible with -ps, -i, -r).Default hex.
    -c, --cols         format <cols> octets per line. Default 16 (-i 12, --ps 30).
    -E, --ebcdic       show characters in EBCDIC. Default ASCII.
    -g, --groups       number of octets per group in normal output. Default 2.
    -h, --help         print this summary.
    -i, --include      output in C include file style.
    -l, --length       stop after <len> octets.
    -p, --ps           output in postscript plain hexdump style.
    -r, --reverse      reverse operation: convert (or patch) hexdump into ASCII output.
                       * reversing non-hexdump formats require -r<flag> (i.e. -rb, -ri, -rp).
    -s, --seek         start at <seek> bytes/bits in file. Byte/bit postfixes can be used.
    		       * byte/bit postfix units are multiples of 1024.
    		       * bits (kb, mb, etc.) will be rounded down to nearest byte.
    -u, --uppercase    use upper case hex letters.
    -v, --version      show version.

The origin of the program can be read below, and this repository is the continually developed branch forked from the origin, https://github.com/felixge/go-xxd

(Old below README)


go-xxd

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

OSX 10.10.1:

xxd native:

$ time xxd image.jpg > /dev/null

real	0m0.205s
user	0m0.202s
sys	0m0.003s

xxd.go (original version from reddit):

$ go build xxd.go && time ./xxd image.jpg > /dev/null

real	0m5.914s
user	0m3.598s
sys	0m2.318s

xxd.go (optimized):

$ go build xxd.go && time ./xxd image.jpg > /dev/null

real	0m0.138s
user	0m0.133s
sys	0m0.004s

Ubuntu 14.04 (inside VirtualBox):

xxd native:

$ time xxd image.jpg > /dev/null

real	0m0.273s
user	0m0.017s
sys	0m0.231s

xxd.go (original version from reddit):

$ go build xxd.go && time ./xxd image.jpg > /dev/null

real	0m5.856s
user	0m3.517s
sys	0m1.897s

xxd.go (optimized):

$ go build xxd.go && time ./xxd image.jpg > /dev/null

real	0m0.233s
user	0m0.021s
sys	0m0.207s