Skip to content

Commit

Permalink
Get back some ns by removing the extra inferance added by binary support
Browse files Browse the repository at this point in the history
benchstat old new
name                                   old time/op    new time/op    delta
LogEmpty-8                               15.2ns ±14%    13.4ns ± 3%  -12.11%  (p=0.008 n=5+5)
Disabled-8                               2.50ns ± 1%    2.28ns ± 6%   -8.81%  (p=0.008 n=5+5)
Info-8                                   44.4ns ± 1%    36.4ns ± 4%  -17.99%  (p=0.008 n=5+5)
ContextFields-8                          47.6ns ± 1%    39.4ns ± 7%  -17.30%  (p=0.008 n=5+5)
ContextAppend-8                          18.9ns ± 4%    15.2ns ± 4%  -19.68%  (p=0.008 n=5+5)
LogFields-8                               181ns ± 2%     173ns ± 2%   -4.63%  (p=0.008 n=5+5)
LogArrayObject-8                          530ns ± 3%     487ns ± 3%   -8.11%  (p=0.008 n=5+5)
LogFieldType/Int-8                       29.5ns ± 3%    28.8ns ± 2%     ~     (p=0.167 n=5+5)
LogFieldType/Interface-8                  180ns ± 7%     175ns ± 4%     ~     (p=0.579 n=5+5)
LogFieldType/Interface(Object)-8         87.8ns ± 3%    80.5ns ± 1%   -8.29%  (p=0.008 n=5+5)
LogFieldType/Object-8                    83.7ns ± 2%    77.2ns ± 3%   -7.76%  (p=0.008 n=5+5)
LogFieldType/Bools-8                     34.6ns ± 3%    32.3ns ± 6%   -6.64%  (p=0.032 n=5+5)
LogFieldType/Float-8                     43.0ns ± 4%    40.5ns ± 4%   -5.86%  (p=0.016 n=5+5)
LogFieldType/Str-8                       29.8ns ± 2%    26.5ns ± 5%  -11.01%  (p=0.008 n=5+5)
LogFieldType/Err-8                       32.8ns ± 2%    29.8ns ± 4%   -9.21%  (p=0.008 n=5+5)
LogFieldType/Durs-8                       309ns ± 3%     304ns ± 3%     ~     (p=0.238 n=5+5)
LogFieldType/Floats-8                     175ns ± 2%     174ns ± 3%     ~     (p=0.968 n=5+5)
LogFieldType/Strs-8                      51.0ns ± 3%    48.4ns ± 6%   -5.06%  (p=0.032 n=5+5)
LogFieldType/Dur-8                       44.5ns ± 3%    41.3ns ± 3%   -7.11%  (p=0.008 n=5+5)
LogFieldType/Interface(Objects)-8         758ns ± 3%     760ns ± 6%     ~     (p=1.000 n=5+5)
LogFieldType/Interfaces-8                 772ns ± 5%     762ns ± 4%     ~     (p=0.794 n=5+5)
LogFieldType/Bool-8                      28.0ns ± 6%    26.5ns ± 9%     ~     (p=0.143 n=5+5)
LogFieldType/Ints-8                      49.6ns ± 2%    46.2ns ± 2%   -6.70%  (p=0.008 n=5+5)
LogFieldType/Errs-8                      46.5ns ±11%    40.9ns ± 4%  -11.92%  (p=0.008 n=5+5)
LogFieldType/Time-8                       115ns ± 3%     113ns ± 3%     ~     (p=0.167 n=5+5)
LogFieldType/Times-8                      810ns ± 1%     811ns ± 3%     ~     (p=0.889 n=5+5)
ContextFieldType/Errs-8                   158ns ± 6%     156ns ±12%     ~     (p=1.000 n=5+5)
ContextFieldType/Times-8                  165ns ±11%     173ns ± 9%     ~     (p=0.651 n=5+5)
ContextFieldType/Interface-8              289ns ±13%     287ns ±11%     ~     (p=0.690 n=5+5)
ContextFieldType/Interface(Object)-8      285ns ±12%     297ns ± 6%     ~     (p=0.238 n=5+5)
ContextFieldType/Interface(Objects)-8     941ns ± 6%     941ns ± 5%     ~     (p=1.000 n=5+5)
ContextFieldType/Object-8                 201ns ± 5%     210ns ±12%     ~     (p=0.262 n=5+5)
ContextFieldType/Ints-8                   173ns ±10%     165ns ± 9%     ~     (p=0.198 n=5+5)
ContextFieldType/Floats-8                 297ns ± 6%     292ns ± 7%     ~     (p=0.579 n=5+5)
ContextFieldType/Timestamp-8              174ns ± 9%     174ns ±11%     ~     (p=0.810 n=5+5)
ContextFieldType/Durs-8                   445ns ± 9%     425ns ± 3%     ~     (p=0.151 n=5+5)
ContextFieldType/Interfaces-8             944ns ± 6%     876ns ±10%     ~     (p=0.095 n=5+5)
ContextFieldType/Strs-8                   179ns ±11%     165ns ±13%     ~     (p=0.135 n=5+5)
ContextFieldType/Dur-8                    158ns ± 8%     160ns ±19%     ~     (p=1.000 n=5+5)
ContextFieldType/Time-8                   152ns ±15%     148ns ±14%     ~     (p=0.952 n=5+5)
ContextFieldType/Str-8                    146ns ±12%     147ns ±16%     ~     (p=0.841 n=5+5)
ContextFieldType/Err-8                    138ns ±12%     145ns ±17%     ~     (p=0.595 n=5+5)
ContextFieldType/Int-8                    145ns ±10%     146ns ±13%     ~     (p=0.873 n=5+5)
ContextFieldType/Float-8                  181ns ± 9%     162ns ±12%     ~     (p=0.151 n=5+5)
ContextFieldType/Bool-8                   153ns ±10%     131ns ±19%     ~     (p=0.063 n=5+5)
ContextFieldType/Bools-8                  149ns ±11%     160ns ±16%     ~     (p=0.500 n=5+5)
  • Loading branch information
rs committed May 10, 2018
1 parent a572c9d commit ea1184b
Show file tree
Hide file tree
Showing 23 changed files with 578 additions and 863 deletions.
96 changes: 48 additions & 48 deletions array.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,163 +33,163 @@ func (*Array) MarshalZerologArray(*Array) {
}

func (a *Array) write(dst []byte) []byte {
dst = appendArrayStart(dst)
dst = enc.AppendArrayStart(dst)
if len(a.buf) > 0 {
dst = append(append(dst, a.buf...))
}
dst = appendArrayEnd(dst)
dst = enc.AppendArrayEnd(dst)
arrayPool.Put(a)
return dst
}

// Object marshals an object that implement the LogObjectMarshaler
// interface and append it to the array.
// interface and enc.Append it to the array.
func (a *Array) Object(obj LogObjectMarshaler) *Array {
e := Dict()
obj.MarshalZerologObject(e)
e.buf = appendEndMarker(e.buf)
a.buf = append(appendArrayDelim(a.buf), e.buf...)
e.buf = enc.AppendEndMarker(e.buf)
a.buf = append(enc.AppendArrayDelim(a.buf), e.buf...)
eventPool.Put(e)
return a
}

// Str append the val as a string to the array.
// Str enc.Append the val as a string to the array.
func (a *Array) Str(val string) *Array {
a.buf = appendString(appendArrayDelim(a.buf), val)
a.buf = enc.AppendString(enc.AppendArrayDelim(a.buf), val)
return a
}

// Bytes append the val as a string to the array.
// Bytes enc.Append the val as a string to the array.
func (a *Array) Bytes(val []byte) *Array {
a.buf = appendBytes(appendArrayDelim(a.buf), val)
a.buf = enc.AppendBytes(enc.AppendArrayDelim(a.buf), val)
return a
}

// Hex append the val as a hex string to the array.
// Hex enc.Append the val as a hex string to the array.
func (a *Array) Hex(val []byte) *Array {
a.buf = appendHex(appendArrayDelim(a.buf), val)
a.buf = enc.AppendHex(enc.AppendArrayDelim(a.buf), val)
return a
}

// Err append the err as a string to the array.
// Err enc.Append the err as a string to the array.
func (a *Array) Err(err error) *Array {
a.buf = appendError(appendArrayDelim(a.buf), err)
a.buf = enc.AppendError(enc.AppendArrayDelim(a.buf), err)
return a
}

// Bool append the val as a bool to the array.
// Bool enc.Append the val as a bool to the array.
func (a *Array) Bool(b bool) *Array {
a.buf = appendBool(appendArrayDelim(a.buf), b)
a.buf = enc.AppendBool(enc.AppendArrayDelim(a.buf), b)
return a
}

// Int append i as a int to the array.
// Int enc.Append i as a int to the array.
func (a *Array) Int(i int) *Array {
a.buf = appendInt(appendArrayDelim(a.buf), i)
a.buf = enc.AppendInt(enc.AppendArrayDelim(a.buf), i)
return a
}

// Int8 append i as a int8 to the array.
// Int8 enc.Append i as a int8 to the array.
func (a *Array) Int8(i int8) *Array {
a.buf = appendInt8(appendArrayDelim(a.buf), i)
a.buf = enc.AppendInt8(enc.AppendArrayDelim(a.buf), i)
return a
}

// Int16 append i as a int16 to the array.
// Int16 enc.Append i as a int16 to the array.
func (a *Array) Int16(i int16) *Array {
a.buf = appendInt16(appendArrayDelim(a.buf), i)
a.buf = enc.AppendInt16(enc.AppendArrayDelim(a.buf), i)
return a
}

// Int32 append i as a int32 to the array.
// Int32 enc.Append i as a int32 to the array.
func (a *Array) Int32(i int32) *Array {
a.buf = appendInt32(appendArrayDelim(a.buf), i)
a.buf = enc.AppendInt32(enc.AppendArrayDelim(a.buf), i)
return a
}

// Int64 append i as a int64 to the array.
// Int64 enc.Append i as a int64 to the array.
func (a *Array) Int64(i int64) *Array {
a.buf = appendInt64(appendArrayDelim(a.buf), i)
a.buf = enc.AppendInt64(enc.AppendArrayDelim(a.buf), i)
return a
}

// Uint append i as a uint to the array.
// Uint enc.Append i as a uint to the array.
func (a *Array) Uint(i uint) *Array {
a.buf = appendUint(appendArrayDelim(a.buf), i)
a.buf = enc.AppendUint(enc.AppendArrayDelim(a.buf), i)
return a
}

// Uint8 append i as a uint8 to the array.
// Uint8 enc.Append i as a uint8 to the array.
func (a *Array) Uint8(i uint8) *Array {
a.buf = appendUint8(appendArrayDelim(a.buf), i)
a.buf = enc.AppendUint8(enc.AppendArrayDelim(a.buf), i)
return a
}

// Uint16 append i as a uint16 to the array.
// Uint16 enc.Append i as a uint16 to the array.
func (a *Array) Uint16(i uint16) *Array {
a.buf = appendUint16(appendArrayDelim(a.buf), i)
a.buf = enc.AppendUint16(enc.AppendArrayDelim(a.buf), i)
return a
}

// Uint32 append i as a uint32 to the array.
// Uint32 enc.Append i as a uint32 to the array.
func (a *Array) Uint32(i uint32) *Array {
a.buf = appendUint32(appendArrayDelim(a.buf), i)
a.buf = enc.AppendUint32(enc.AppendArrayDelim(a.buf), i)
return a
}

// Uint64 append i as a uint64 to the array.
// Uint64 enc.Append i as a uint64 to the array.
func (a *Array) Uint64(i uint64) *Array {
a.buf = appendUint64(appendArrayDelim(a.buf), i)
a.buf = enc.AppendUint64(enc.AppendArrayDelim(a.buf), i)
return a
}

// Float32 append f as a float32 to the array.
// Float32 enc.Append f as a float32 to the array.
func (a *Array) Float32(f float32) *Array {
a.buf = appendFloat32(appendArrayDelim(a.buf), f)
a.buf = enc.AppendFloat32(enc.AppendArrayDelim(a.buf), f)
return a
}

// Float64 append f as a float64 to the array.
// Float64 enc.Append f as a float64 to the array.
func (a *Array) Float64(f float64) *Array {
a.buf = appendFloat64(appendArrayDelim(a.buf), f)
a.buf = enc.AppendFloat64(enc.AppendArrayDelim(a.buf), f)
return a
}

// Time append t formated as string using zerolog.TimeFieldFormat.
// Time enc.Append t formated as string using zerolog.TimeFieldFormat.
func (a *Array) Time(t time.Time) *Array {
a.buf = appendTime(appendArrayDelim(a.buf), t, TimeFieldFormat)
a.buf = enc.AppendTime(enc.AppendArrayDelim(a.buf), t, TimeFieldFormat)
return a
}

// Dur append d to the array.
// Dur enc.Append d to the array.
func (a *Array) Dur(d time.Duration) *Array {
a.buf = appendDuration(appendArrayDelim(a.buf), d, DurationFieldUnit, DurationFieldInteger)
a.buf = enc.AppendDuration(enc.AppendArrayDelim(a.buf), d, DurationFieldUnit, DurationFieldInteger)
return a
}

// Interface append i marshaled using reflection.
// Interface enc.Append i marshaled using reflection.
func (a *Array) Interface(i interface{}) *Array {
if obj, ok := i.(LogObjectMarshaler); ok {
return a.Object(obj)
}
a.buf = appendInterface(appendArrayDelim(a.buf), i)
a.buf = enc.AppendInterface(enc.AppendArrayDelim(a.buf), i)
return a
}

// IPAddr adds IPv4 or IPv6 address to the array
func (a *Array) IPAddr(ip net.IP) *Array {
a.buf = appendIPAddr(appendArrayDelim(a.buf), ip)
a.buf = enc.AppendIPAddr(enc.AppendArrayDelim(a.buf), ip)
return a
}

// IPPrefix adds IPv4 or IPv6 Prefix (IP + mask) to the array
func (a *Array) IPPrefix(pfx net.IPNet) *Array {
a.buf = appendIPPrefix(appendArrayDelim(a.buf), pfx)
a.buf = enc.AppendIPPrefix(enc.AppendArrayDelim(a.buf), pfx)
return a
}

// MACAddr adds a MAC (Ethernet) address to the array
func (a *Array) MACAddr(ha net.HardwareAddr) *Array {
a.buf = appendMACAddr(appendArrayDelim(a.buf), ha)
a.buf = enc.AppendMACAddr(enc.AppendArrayDelim(a.buf), ha)
return a
}
Loading

0 comments on commit ea1184b

Please sign in to comment.