Created
December 1, 2017 18:27
-
-
Save sbrichardson/694cb62df2f076aac5af600a45662567 to your computer and use it in GitHub Desktop.
RLog Benchmark Class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RLog { | |
contructor(title) { | |
this.kind = 'Method Log' | |
this.name = title | |
this.book = { | |
new: true, | |
errors: [], | |
successes: [], | |
errorCount: 0, | |
successCount: 0, | |
start: null, | |
finish: null, | |
benchStart: null, | |
benchFinish: null, | |
duration: null | |
} | |
} | |
} | |
RLog.prototype.log = (type, entry) => { | |
check(type, String) | |
check(entry, Match.OneOf(String, Date, Number, Boolean, Object, Array)) | |
if (this.book.new) { | |
this.book.benchStart = process.hrtime() | |
this.book.new = false | |
this.book.start = new Date() | |
} | |
if (type === "err") { | |
this.book.errors.push(entry) | |
this.book.errorCount++ | |
} | |
if (type === "good") { | |
this.book.successes.push(entry) | |
this.book.successCount++ | |
} | |
return | |
} | |
RLog.prototype.start = () => { | |
this.book.benchStart = process.hrtime() | |
this.book.new = false | |
this.book.start = new Date() | |
return | |
} | |
RLog.prototype.finish = () => { | |
this.book.benchFinish = process.hrtime(this.book.benchStart) | |
this.book.finish = new Date() | |
if (this.book.benchFinish) { | |
this.book.duration = ((this.book.benchFinish[0] || 0) + ' seconds and ' + ((this.book.benchFinish[1] || 0)/1000000) + ' ms') || "Benchmark Error" | |
} | |
return | |
} | |
RLog.prototype.duration = () => { | |
if(this.book.benchFinish) { | |
console.info('\n** Benchmark Results **\nName: '+ this.name + '\nTime: ' + (this.book.benchFinish[0] || 0) + ' seconds and ' + ((this.book.benchFinish[1] || 0)/1000000) + ' ms') | |
} | |
return | |
} | |
RLog.prototype.print = () => { | |
console.info('\n** Current LogBook **\nName: ' + this.name + '\nLog:\n' + util.inspect(this.book, {depth: null, colors: true})) | |
return | |
} | |
RLog.prototype.rError = ops => { | |
this.book.name = ops.name | |
this.book.type = ops.type | |
this.book.message = ops.message | |
this.book.detail = ops.detail | |
this.book.extendedInfo = ops.extendedInfo | |
this.book.errorCode = ops.errorCode | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Older Version that included a command line chart output:
usage