Skip to content

Commit

Permalink
Add benchmarks for counter (same as gauge) (#596)
Browse files Browse the repository at this point in the history
  • Loading branch information
yosiat authored Oct 26, 2023
1 parent c0f2297 commit 629cd5b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
42 changes: 42 additions & 0 deletions benchmarks/counter.js
Original file line number Diff line number Diff line change
@@ -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();
}
1 change: 1 addition & 0 deletions benchmarks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down

0 comments on commit 629cd5b

Please sign in to comment.