diff --git a/benchmark/call-familySync.js b/benchmark/call-familySync.js new file mode 100644 index 0000000..841be94 --- /dev/null +++ b/benchmark/call-familySync.js @@ -0,0 +1,7 @@ +const performance = require('perf_hooks').performance; +const libc = require('..'); + +const now = performance.now(); +libc.familySync(); + +console.log(`[family] Time Spent ${performance.now() - now}ms`); diff --git a/benchmark/call-isNonGlibcLinuxSync.js b/benchmark/call-isNonGlibcLinuxSync.js new file mode 100644 index 0000000..3a8f08c --- /dev/null +++ b/benchmark/call-isNonGlibcLinuxSync.js @@ -0,0 +1,7 @@ +const performance = require('perf_hooks').performance; +const libc = require('..'); + +const now = performance.now(); +libc.isNonGlibcLinuxSync(); + +console.log(`[isNonGlibcLinux] Time Spent ${performance.now() - now}ms`); diff --git a/benchmark/call-versionSync.js b/benchmark/call-versionSync.js new file mode 100644 index 0000000..1db7d7e --- /dev/null +++ b/benchmark/call-versionSync.js @@ -0,0 +1,7 @@ +const performance = require('perf_hooks').performance; +const libc = require('..'); + +const now = performance.now(); +libc.versionSync(); + +console.log(`[versionSync] Time Spent ${performance.now() - now}ms`); diff --git a/benchmark/detect-libc.js b/benchmark/detect-libc.js new file mode 100644 index 0000000..a5e21bf --- /dev/null +++ b/benchmark/detect-libc.js @@ -0,0 +1,39 @@ +const Benchmark = require('benchmark'); +const suite = new Benchmark.Suite(); +const libc = require('../'); + +suite.add('family', async function () { + await libc.family(); +}); + +suite.add('familySync', function () { + libc.familySync(); +}); + +suite.add('version', async function () { + await libc.version(); +}); + +suite.add('versionSync', function () { + libc.versionSync(); +}); + +suite.add('isNonGlibcLinux', async function () { + await libc.isNonGlibcLinux(); +}); + +suite.add('isNonGlibcLinuxSync', function () { + 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 + }); diff --git a/package.json b/package.json index aeb7cc1..8b12b2b 100644 --- a/package.json +++ b/package.json @@ -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", @@ -26,6 +28,7 @@ "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"