diff --git a/benchmarks/counter.js b/benchmarks/counter.js new file mode 100644 index 00000000..9607b493 --- /dev/null +++ b/benchmarks/counter.js @@ -0,0 +1,42 @@ +'use strict'; + +const { getLabelNames, labelCombinationFactory } = require('./utils/labels'); + +module.exports = setupCounterSuite; + +function setupCounterSuite(suite) { + suite.add( + 'inc', + labelCombinationFactory([], (client, { Counter }, labels) => + Counter.inc(labels, 1), + ), + { teardown, setup: setup(0) }, + ); + + suite.add( + 'inc with labels', + labelCombinationFactory([8, 8], (client, { Counter }, labels) => + Counter.inc(labels, 1), + ), + { teardown, setup: setup(2) }, + ); +} + +function setup(labelCount) { + return client => { + const registry = new client.Registry(); + + const Counter = new client.Counter({ + name: 'Counter', + help: 'Counter', + labelNames: getLabelNames(labelCount), + registers: [registry], + }); + + return { registry, Counter }; + }; +} + +function teardown(client, { registry }) { + registry.clear(); +} diff --git a/benchmarks/index.js b/benchmarks/index.js index 645a4acd..ff936b1c 100644 --- a/benchmarks/index.js +++ b/benchmarks/index.js @@ -9,6 +9,7 @@ const benchmarks = createRegressionBenchmark(currentClient, [ benchmarks.suite('registry', require('./registry')); benchmarks.suite('histogram', require('./histogram')); +benchmarks.suite('counter', require('./counter')); benchmarks.suite('gauge', require('./gauge')); benchmarks.suite('summary', require('./summary')); benchmarks.run().catch(err => {