This directory contains performance benchmarks for node-casbin.
To run the benchmarks locally:
yarn benchmark
This will:
The benchmark suite tests the performance of:
enforce() (async) - both allow and deny casesenforceSync() - both allow and deny casesgetRolesForUser() - get user roleshasRoleForUser() - check if user has a specific roleenforce() (async) - attribute-based access controlenforceSync() - attribute-based access controlenforce() (async) - basic access controlenforceSync() - basic access controlgetPolicy() - retrieve all policieshasPolicy() - check if policy existsgetFilteredPolicy() - retrieve filtered policiesThe benchmark workflow automatically runs on every Pull Request:
The PR comment will show:
If your PR shows performance regressions:
Small regressions (<5%) are generally acceptable if:
To add new benchmarks, edit benchmark/benchmark.ts:
// Create a new suite const mySuite = createSuite('My Feature'); mySuite .add('My benchmark', { defer: true, // for async tests fn: async (deferred: Benchmark.Deferred) => { await myFunction(); deferred.resolve(); }, }) .on('complete', () => { resolve(); }) .run({ async: true });
For synchronous tests, omit the defer option:
mySuite.add('My sync benchmark', () => { mySyncFunction(); });