BuaBook / kdb-common

kdb+ Core Libraries and Utilities
Apache License 2.0
51 stars 16 forks source link

log: Add support for slf4j-style parameterised logging #51

Closed jasraj closed 3 years ago

jasraj commented 3 years ago

Testing:

/ model name      : Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz

/ Setup
q) .require.lib`log; .log.setLevel`DEBUG;
q) sym:`a;
q) dict:`a`b`c!1 2 3;
q) table:flip `a`b`c!2?/:(`3; 1f; 100j);

// Logging enabled
q) .log.info "A symbol: ",string sym;                                   / Old format
q) if[.log.isLoggingAt `DEBUG; .log.debug "A symbol: ",string sym ];    / Old with log level check
q) .log.info ("A symbol: {}"; sym);                                     / New (slf4j-style) format

// Logging disabled
q) .log.trace "A symbol: ",string sym;                                  / Old format
q) if[.log.isLoggingAt `TRACE; .log.trace "A symbol: ",string sym ];    / Old with log level check
q) .log.trace ("A symbol: {}"; sym);                                    / New (slf4j-style) format

Results:

Outputs Format Iterations ts
YES Old 1000 Atom: 32 4196240
Dict: 18 4195840
* Table: 118 4195904
YES Old with check 1000 Atom: 36 4196496
Dict: 18 4196096
* Table: 115 4196160
YES New 1000 Atom: 33 4195456
Dict: 21 4195344
* Table: 118 4195344
NO Old 10000 Atom: 5 2336
Dict: 94 1808
* Table: 196 2464
NO Old with check 10000 Atom: 12 3120
Dict: 11 2208
* Table: 12 2208
NO New 10000 Atom: 2 1984
Dict: 2 1680
* Table: 2 1712

When the log level is output to standard out / standard error the performance of all 3 mechanism is more-or-less the same.

However, when the log level is disabled, there is a significant increase in performance with the new logging format, particularly if the object to be printed is a complex object (generally deferring to .Q.s1).