Last active
May 11, 2018 16:05
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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