Use concrete types for path steps (#129)

Rather than representing each path step as an interface,
use concrete types instead. This provides some performance benefits as
it reduces the amount of virtual function calls and also provides the
ability for the compiler to inline method calls.

This is technically a breaking change, but since each of the path step
interfaces were explicitly implemented in such a way that they couldn't
be implemented directly (due to the presence of an unexported method),
the only way someone could have been depending on these as interfaces is
if they embedded the interface into another interface. Static analysis of
all code at Google and publicly available on GitHub shows that this is
not a problem.

The performance benefits of this change is significant:

benchmark                               old ns/op     new ns/op     delta
BenchmarkBytes/64KiB/EqualFilter0-4     80551394      46592605      -42.16%
BenchmarkBytes/64KiB/EqualFilter1-4     102922132     69974509      -32.01%
BenchmarkBytes/64KiB/EqualFilter2-4     159009935     94474812      -40.59%
BenchmarkBytes/64KiB/EqualFilter3-4     181231264     124601102     -31.25%
BenchmarkBytes/64KiB/EqualFilter4-4     189775228     148864070     -21.56%
BenchmarkBytes/64KiB/EqualFilter5-4     285065469     175198907     -38.54%

benchmark                               old MB/s     new MB/s     speedup
BenchmarkBytes/64KiB/EqualFilter0-4     1.63         2.81         1.72x
BenchmarkBytes/64KiB/EqualFilter1-4     1.27         1.87         1.47x
BenchmarkBytes/64KiB/EqualFilter2-4     0.82         1.39         1.70x
BenchmarkBytes/64KiB/EqualFilter3-4     0.72         1.05         1.46x
BenchmarkBytes/64KiB/EqualFilter4-4     0.69         0.88         1.28x
BenchmarkBytes/64KiB/EqualFilter5-4     0.46         0.75         1.63x

benchmark                               old allocs     new allocs     delta
BenchmarkBytes/64KiB/EqualFilter0-4     133            134            +0.75%
BenchmarkBytes/64KiB/EqualFilter1-4     134            134            +0.00%
BenchmarkBytes/64KiB/EqualFilter2-4     135            135            +0.00%
BenchmarkBytes/64KiB/EqualFilter3-4     135            135            +0.00%
BenchmarkBytes/64KiB/EqualFilter4-4     136            136            +0.00%
BenchmarkBytes/64KiB/EqualFilter5-4     136            136            +0.00%

benchmark                               old bytes     new bytes     delta
BenchmarkBytes/64KiB/EqualFilter0-4     6632417       6632523       +0.00%
BenchmarkBytes/64KiB/EqualFilter1-4     6632416       6632464       +0.00%
BenchmarkBytes/64KiB/EqualFilter2-4     6632464       6632507       +0.00%
BenchmarkBytes/64KiB/EqualFilter3-4     6632502       6632483       -0.00%
BenchmarkBytes/64KiB/EqualFilter4-4     6632652       6632668       +0.00%
BenchmarkBytes/64KiB/EqualFilter5-4     6632604       6632659       +0.00%
3 files changed
tree: b535dad1a74657e2f38af13d73226439ed08e1f9
  1. cmp/
  2. .travis.yml
  3. CONTRIBUTING.md
  4. go.mod
  5. LICENSE
  6. README.md
README.md

Package for equality of Go values

GoDoc Build Status

This package is intended to be a more powerful and safer alternative to reflect.DeepEqual for comparing whether two values are semantically equal.

The primary features of cmp are:

  • When the default behavior of equality does not suit the needs of the test, custom equality functions can override the equality operation. For example, an equality function may report floats as equal so long as they are within some tolerance of each other.

  • Types that have an Equal method may use that method to determine equality. This allows package authors to determine the equality operation for the types that they define.

  • If no custom equality functions are used and no Equal method is defined, equality is determined by recursively comparing the primitive kinds on both values, much like reflect.DeepEqual. Unlike reflect.DeepEqual, unexported fields are not compared by default; they result in panics unless suppressed by using an Ignore option (see cmpopts.IgnoreUnexported) or explicitly compared using the AllowUnexported option.

See the GoDoc documentation for more information.

This is not an official Google product.

Install

go get -u github.com/google/go-cmp/cmp

License

BSD - See LICENSE file