stevedomin/termtable — pull request #1 by jmoiron (2013-10-11 09:04:05+00:00)
Title: make Render return a string, optimize it, add some tests and benchmarks

Hi Steve,

I remembered your post on termtable on Go+ and had use for it (tabularizing sql results for a little webapp I'm writing), but I noticed that t.Render() uses Println to print to the console instead of returning a string!

That seems very inflexible, so I changed that to return a string. In addition, I changed Render() to use a `bytes.Buffer` instead of adding strings together, because it is less allocatey and a bit faster, especially for large tables. I added a simple test for one of the examples in the README and a benchmark to show that my changes are sensible:

```
jmoiron@sanji:~/dev/go/termtable$ go test -bench . -benchmem
PASS
BenchmarkRenderBuffer	100000	22116 ns/op	3251 B/op	174 allocs/op
BenchmarkRenderString	100000	27378 ns/op	8037 B/op	209 allocs/op
ok	_/mnt/omocha/jmoiron/dev/go/termtable	5.473s
```

This was a pretty trivial change; a lot more could be got out of converting a lot of the internal API to (re)use []bytes in places and you could also avoid the conversion from string to []byte.

[Embrace the []byte!](http://jmoiron.net/blog/buffers-and-allocation-go-and-python/)