From 4a4416547eaa4ff2d1f119627d6a4989b785ad23 Mon Sep 17 00:00:00 2001 From: Ron Korving Date: Wed, 4 Jan 2017 19:27:26 +0900 Subject: [PATCH] Added benchmark script --- Makefile | 3 +++ bench.js | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 2 +- test.js | 2 +- 4 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 bench.js diff --git a/Makefile b/Makefile index bec14ef..d64bd36 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,9 @@ install: test: npm test +bench: + node ./bench.js + # target: lint, Lints every JavaScript file in the project that are staged to be comitted. lint: ./scripts/lint-staged.sh diff --git a/bench.js b/bench.js new file mode 100644 index 0000000..4d3326f --- /dev/null +++ b/bench.js @@ -0,0 +1,63 @@ +var graylog = require('./graylog'); +var fs = require('fs'); +var servers = [ + { 'host': '127.0.0.1', 'port': 12201 } +]; + +var client = new graylog.graylog({ + servers: servers, + facility: 'node-graylog benchmark' +}); + + +console.log('Deflate:', client.deflate); +console.log(''); + +console.time('small message'); + +var i = 0; +var count = 20000; +var small = 'h'.repeat(2500); +var big = 'h'.repeat(25000); +var bigRandom = require('crypto').randomBytes(20000).toString('base64'); + + +function log(str, label, i, n, cb) { + if (i === 0) { + console.time(label + ' x' + n); + } + + if (i === n) { + console.timeEnd(label + ' x' + n); + cb(); + } else { + client.log('test', str); + setImmediate(log, str, label, i + 1, n, cb); + } +} + +function testSmall(cb) { + log(small, 'small', 0, 20000, cb); +} + +function testBig(cb) { + log(big, 'big', 0, 10000, cb); +} + +function testBigAndRandom(cb) { + log(bigRandom, 'bigAndRandom', 0, 10000, cb); +} + +function close() { + client.close(function () { + console.log(''); + console.log('Insertion complete. Please check', 'http://' + servers[0].host + ':3000', 'and verify that insertion was successfull'); + }); +} + +testSmall(function () { + testBig(function () { + testBigAndRandom(close); + }); +}); + diff --git a/package.json b/package.json index 121bb32..6ba0a62 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ } ], "devDependencies": { - "jshint": "0.9.1" + "jshint": "2.9.2" }, "engines": { "node": ">=0.6.11" diff --git a/test.js b/test.js index 373810e..4511065 100644 --- a/test.js +++ b/test.js @@ -77,7 +77,7 @@ try { facility: 'Test logger / Node.JS Test Script', deflate: 'not an option' }); - throw new Error('should not get here') + throw new Error('should not get here'); } catch (err) { assert( err.message === 'deflate must be one of "optimal", "always", or "never". was "not an option"',