Skip to content

Commit

Permalink
chore: add benchmark files
Browse files Browse the repository at this point in the history
  • Loading branch information
H4ad committed Jun 16, 2023
1 parent d49b8d3 commit 0d170db
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 1 deletion.
6 changes: 6 additions & 0 deletions benchmark/call-familySync.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const libc = require('..');

const now = performance.now();
const result = libc.familySync();

console.log(`[family] Time Spent ${performance.now() - now}ms`);
6 changes: 6 additions & 0 deletions benchmark/call-isNonGlibcLinuxSync.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const libc = require('..');

const now = performance.now();
const result = libc.isNonGlibcLinuxSync();

console.log(`[isNonGlibcLinux] Time Spent ${performance.now() - now}ms`);
6 changes: 6 additions & 0 deletions benchmark/call-versionSync.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const libc = require('..');

const now = performance.now();
const result = libc.versionSync();

console.log(`[versionSync] Time Spent ${performance.now() - now}ms`);
39 changes: 39 additions & 0 deletions benchmark/detect-libc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const Benchmark = require('benchmark');
const suite = new Benchmark.Suite();
const libc = require('../');

suite.add('family', async function () {
const result = await libc.family();
});

suite.add('familySync', function () {
const result = libc.familySync();
});

suite.add('version', async function () {
const result = await libc.version();
});

suite.add('versionSync', function () {
const result = libc.versionSync();
});

suite.add('isNonGlibcLinux', async function () {
const result = await libc.isNonGlibcLinux();
});

suite.add('isNonGlibcLinuxSync', function () {
const result = libc.isNonGlibcLinuxSync();
});

suite
// add listeners
.on('cycle', function (event) {
console.log(String(event.target));
})
.on('complete', function () {
console.log('Fastest operation is ' + this.filter('fastest').map('name'));
})
.run({
async: true
});
10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"index.d.ts"
],
"scripts": {
"test": "semistandard && nyc --reporter=lcov --check-coverage --branches=100 ava test/unit.js"
"test": "semistandard && nyc --reporter=lcov --check-coverage --branches=100 ava test/unit.js",
"bench": "node benchmark/detect-libc",
"bench:calls": "node benchmark/call-familySync.js && sleep 1 && node benchmark/call-isNonGlibcLinuxSync.js && sleep 1 && node benchmark/call-versionSync.js"
},
"repository": {
"type": "git",
Expand All @@ -26,11 +28,17 @@
"license": "Apache-2.0",
"devDependencies": {
"ava": "^2.4.0",
"benchmark": "^2.1.4",
"nyc": "^15.1.0",
"proxyquire": "^2.1.3",
"semistandard": "^14.2.3"
},
"engines": {
"node": ">=8"
},
"semistandard": {
"ignore": [
"benchmark/"
]
}
}

0 comments on commit 0d170db

Please sign in to comment.