Skip to content

Instantly share code, notes, and snippets.

@s-h-a-d-o-w
Last active May 11, 2018 16:05
Show Gist options
  • Save s-h-a-d-o-w/c0b7ee374db044a21a6b5b1e99d269f0 to your computer and use it in GitHub Desktop.
Save s-h-a-d-o-w/c0b7ee374db044a21a6b5b1e99d269f0 to your computer and use it in GitHub Desktop.
Node.js benchmark code for comparing process listers (example: Spotify.exe)
const Benchmark = require('benchmark');
const WmiClient = require('wmi-client');
const {snapshot} = require("process-list");
const ps = require('ps-node');
const suite = new Benchmark.Suite;
let wmi = new WmiClient();
// Purpose: See which is fastest at retrieving a suitable data set, not necessarily narrowed down to
// the data actually needed yet.
// Spotify.exe used as an example for optimization, since e.g. wmic returns more quickly when something like that is specified.
// add tests
suite.add({
name: 'wmi-client',
defer: true,
fn: function(deferred) {
wmi.query('SELECT ProcessId, ParentProcessId FROM Win32_Process where Name="Spotify.exe"', function (err, result) {
deferred.resolve();
})
},
})
.add({
name: 'process-list',
defer: true,
fn: function(deferred) {
snapshot('name', 'pid', 'ppid').then(tasks => {
deferred.resolve();
});
},
})
.add({
name: 'ps-node',
defer: true,
fn: function(deferred) {
ps.lookup({command: 'Spotify.exe'}, function(err, resultList) {
deferred.resolve();
});
},
})
// add listeners
.on('cycle', function(event) {
console.log(String(event.target));
})
.on('complete', function() {
console.log('Fastest is ' + this.filter('fastest').map('name'));
})
suite.run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment