Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rework benchmarks #22

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 52 additions & 26 deletions benchmark/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
'use strict'
const bench = require('fastbench')
const noir = require('pino-noir')(['a.b.c'])
const fastRedact = require('..')
const redactNoSerialize = fastRedact({ paths: ['a.b.c'], serialize: false })
const redactWildNoSerialize = fastRedact({ paths: ['a.b.*'], serialize: false })
const redactIntermediateWildNoSerialize = fastRedact({ paths: ['a.*.c'], serialize: false })
const redact = fastRedact({ paths: ['a.b.c'] })
const noirWild = require('pino-noir')(['a.b.*'])
const redactWild = fastRedact({ paths: ['a.b.*'] })
const redactIntermediateWild = fastRedact({ paths: ['a.*.c'] })
const redactIntermediateWildMatchWildOutcome = fastRedact({ paths: ['a.*.c', 'a.*.b', 'a.*.a'] })
const redactStaticMatchWildOutcome = fastRedact({ paths: ['a.b.c', 'a.d.a', 'a.d.b', 'a.d.c'] })
const noirCensorFunction = require('pino-noir')(['a.b.*'], (v) => v + '.')
const redactCensorFunction = fastRedact({ paths: ['a.b.*'], censor: (v) => v + '.', serialize: false })

const obj = {
a: {
const censorFn = (v) => v + '.'

const noir = require('pino-noir')(['aa.b.c'])
const redactNoSerialize = fastRedact({ paths: ['ab.b.c'], serialize: false })
const redactNoSerializeRestore = fastRedact({ paths: ['ac.b.c'], serialize: false })
const noirWild = require('pino-noir')(['ad.b.*'])
const redactWildNoSerialize = fastRedact({ paths: ['ae.b.*'], serialize: false })
const redactWildNoSerializeRestore = fastRedact({ paths: ['af.b.*'], serialize: false })
const redactIntermediateWildNoSerialize = fastRedact({ paths: ['ag.*.c'], serialize: false })
const redactIntermediateWildNoSerializeRestore = fastRedact({ paths: ['ah.*.c'], serialize: false })
const noirJSONSerialize = require('pino-noir')(['aj.b.c']) // `ai` used in pure JSON test.
const redact = fastRedact({ paths: ['ak.b.c'] })
const noirWildJSONSerialize = require('pino-noir')(['al.b.c'])
const redactWild = fastRedact({ paths: ['am.b.*'] })
const redactIntermediateWild = fastRedact({ paths: ['an.*.c'] })
const redactIntermediateWildMatchWildOutcome = fastRedact({ paths: ['ao.*.c', 'ao.*.b', 'ao.*.a'] })
const redactStaticMatchWildOutcome = fastRedact({ paths: ['ap.b.c', 'ap.d.a', 'ap.d.b', 'ap.d.c'] })
const noirCensorFunction = require('pino-noir')(['aq.b.*'], censorFn)
const redactCensorFunction = fastRedact({ paths: ['ar.b.*'], censor: censorFn, serialize: false })

const getObj = (outerKey) => ({
[outerKey]: {
b: {
c: 's'
},
Expand All @@ -25,119 +33,137 @@ const obj = {
c: 's'
}
}
}
})

const max = 500

var run = bench([
function benchNoirV2 (cb) {
const obj = getObj('aa')
for (var i = 0; i < max; i++) {
noir.a(obj.a)
noir.aa(obj.aa)
}
setImmediate(cb)
},
function benchFastRedact (cb) {
const obj = getObj('ab')
for (var i = 0; i < max; i++) {
redactNoSerialize(obj)
}
setImmediate(cb)
},
function benchFastRedactRestore (cb) {
const obj = getObj('ac')
for (var i = 0; i < max; i++) {
redactNoSerialize(obj)
redactNoSerialize.restore(obj)
redactNoSerializeRestore(obj)
redactNoSerializeRestore.restore(obj)
}
setImmediate(cb)
},
function benchNoirV2Wild (cb) {
const obj = getObj('ad')
for (var i = 0; i < max; i++) {
noirWild.a(obj.a)
noirWild.ad(obj.ad)
}
setImmediate(cb)
},
function benchFastRedactWild (cb) {
const obj = getObj('ae')
for (var i = 0; i < max; i++) {
redactWildNoSerialize(obj)
}
setImmediate(cb)
},
function benchFastRedactWildRestore (cb) {
const obj = getObj('af')
for (var i = 0; i < max; i++) {
redactWildNoSerialize(obj)
redactWildNoSerialize.restore(obj)
redactWildNoSerializeRestore(obj)
redactWildNoSerializeRestore.restore(obj)
}
setImmediate(cb)
},
function benchFastRedactIntermediateWild (cb) {
const obj = getObj('ag')
for (var i = 0; i < max; i++) {
redactIntermediateWildNoSerialize(obj)
}
setImmediate(cb)
},
function benchFastRedactIntermediateWildRestore (cb) {
const obj = getObj('ah')
for (var i = 0; i < max; i++) {
redactIntermediateWildNoSerialize(obj)
redactIntermediateWildNoSerialize.restore(obj)
redactIntermediateWildNoSerializeRestore(obj)
redactIntermediateWildNoSerializeRestore.restore(obj)
}
setImmediate(cb)
},
function benchJSONStringify (cb) {
const obj = getObj('ai')
for (var i = 0; i < max; i++) {
JSON.stringify(obj)
}
setImmediate(cb)
},
function benchNoirV2Serialize (cb) {
const obj = getObj('aj')
for (var i = 0; i < max; i++) {
noir.a(obj.a)
noirJSONSerialize.aj(obj.aj)
JSON.stringify(obj)
}
setImmediate(cb)
},
function benchFastRedactSerialize (cb) {
const obj = getObj('ak')
for (var i = 0; i < max; i++) {
redact(obj)
}
setImmediate(cb)
},
function benchNoirV2WildSerialize (cb) {
const obj = getObj('al')
for (var i = 0; i < max; i++) {
noirWild.a(obj.a)
noirWildJSONSerialize.al(obj.al)
JSON.stringify(obj)
}
setImmediate(cb)
},
function benchFastRedactWildSerialize (cb) {
const obj = getObj('am')
for (var i = 0; i < max; i++) {
redactWild(obj)
}
setImmediate(cb)
},
function benchFastRedactIntermediateWildSerialize (cb) {
const obj = getObj('an')
for (var i = 0; i < max; i++) {
redactIntermediateWild(obj)
}
setImmediate(cb)
},
function benchFastRedactIntermediateWildMatchWildOutcomeSerialize (cb) {
const obj = getObj('ao')
for (var i = 0; i < max; i++) {
redactIntermediateWildMatchWildOutcome(obj)
}
setImmediate(cb)
},
function benchFastRedactStaticMatchWildOutcomeSerialize (cb) {
const obj = getObj('ap')
for (var i = 0; i < max; i++) {
redactStaticMatchWildOutcome(obj)
}
setImmediate(cb)
},
function benchNoirV2CensorFunction (cb) {
const obj = getObj('aq')
for (var i = 0; i < max; i++) {
noirCensorFunction.a(obj.a)
noirCensorFunction.aq(obj.aq)
}
setImmediate(cb)
},
function benchFastRedactCensorFunction (cb) {
const obj = getObj('ar')
for (var i = 0; i < max; i++) {
redactCensorFunction(obj)
}
Expand Down
8 changes: 4 additions & 4 deletions lib/rx.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

module.exports = /[^.[\]]+|\[((?:.)*?)\]/g

/*
/*
Regular expression explanation:

Alt 1: /[^.[\]]+/ - Match one or more characters that are *not* a dot (.)
Alt 1: /[^.[\]]+/ - Match one or more characters that are *not* a dot (.)
opening square bracket ([) or closing square bracket (])

Alt 2: /\[((?:.)*?)\]/ - If the char IS dot or square bracket, then create a capture
group (which will be capture group $1) that matches anything
group (which will be capture group $1) that matches anything
within square brackets. Expansion is lazy so it will
stop matching as soon as the first closing bracket is met `]`
stop matching as soon as the first closing bracket is met `]`
(rather than continuing to match until the final closing bracket).
*/