nurugger07/chronos — pull request #16 by BinaryMuse (2014-08-08 03:56:44+00:00)
Title: Implement formatter with pattern matching

While pondering the regular expression required to fix #15, I decided to try to implement the formatter using pattern matching instead. This is the result; the test suite passes (including a new test case for #15), and based on this extremely unscientific benchmark, appears to be faster.

```
$ git checkout master
time mix run benchmark.exs # (5 times)
mix run benchmark.exs 3.39s user 0.12s system 102% cpu 3.425 total
mix run benchmark.exs 3.47s user 0.12s system 102% cpu 3.501 total
mix run benchmark.exs 3.37s user 0.12s system 102% cpu 3.397 total
mix run benchmark.exs 3.36s user 0.12s system 102% cpu 3.396 total
mix run benchmark.exs 3.41s user 0.12s system 102% cpu 3.435 total

$ git checkout bkt-pattern-match-formatter
time mix run benchmark.exs # (5 times)
mix run benchmark.exs 1.57s user 0.12s system 105% cpu 1.597 total
mix run benchmark.exs 1.58s user 0.13s system 106% cpu 1.612 total
mix run benchmark.exs 1.54s user 0.12s system 105% cpu 1.569 total
mix run benchmark.exs 1.50s user 0.12s system 105% cpu 1.527 total
mix run benchmark.exs 1.55s user 0.17s system 105% cpu 1.627 total
```

Benchmark script:

```elixir
Enum.each 1..100000, fn(_n) ->
Chronos.Formatter.strftime({{2012, 12, 21}, {1, 2, 3}}, "%Y-%0m-%0dT%H:%M:%S.000Z")
end
```