Why are you putting the ResetTimer() and StopTimer() calls in there ? Unnecessary AFAIK.
Also, all this test is benchmarking is the time it takes to construct a Field struct. What is the point ? > On Nov 26, 2018, at 1:47 PM, lary...@gmail.com wrote: > > Talking about loggers and ZAP (interesting idea to accommodate API to the > JSON) > The following code gets 40ns/op > type FieldType uint8 > > type Field struct { > Key string > Type FieldType > Integer int64 > String string > Interface interface{} > } > > const ( > // UnknownType is the default field type. Attempting to add it to an > encoder will panic. > UnknownType FieldType = iota > // Int64Type indicates that the field carries an int64. > Uint64Type > ) > > func Uint64(key string, val uint64) Field { > return Field{Key: key, Type: Uint64Type, Integer: int64(val)} > } > > func handleFields(s string, fields ...Field) { > > } > > func BenchmarkZapApi(b *testing.B) { > b.ResetTimer() > for i := 0; i < b.N; i++ { > handleFields("Hello ", > Uint64("world", 0), > Uint64("world", 1), > Uint64("world", 2), > ) > } > b.StopTimer() > } > > > > > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com > <mailto:golang-nuts+unsubscr...@googlegroups.com>. > For more options, visit https://groups.google.com/d/optout > <https://groups.google.com/d/optout>. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.