Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Hack to test speed of launching a sub process in node.js or python
# Launch and time python and node scripts that also launch subprocesses
echo start launch python data subprocess...
date "+%T %s %N"
echo start launch python compiled data subprocess...
date "+%T %s %N"
python mypydatesub.pyc
# make sure you have installed nvm see
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/" ] && . "$NVM_DIR/" # This loads nvm
nvm install v7.6.0
nvm use v7.6.0
echo start launch node subprocess
date "+%T %s %N"
node mynodesub.js
# end of
# now the python script
import subprocess["date", '+%T %s %N'])["date", '+%T %s %N'])
# end of
# also compile this to a pyc file using
$ python
Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import py_compile
>>> py_compile.compile("")
>>> exit()
# now the node.js script
# mynodesub.js
var child_process = require('child_process');
child_process.spawn('date', [ "+%T %s %N" ], { stdio: 'inherit' });
child_process.spawn('date', [ "+%T %s %N" ], { stdio: 'inherit' });
# end of mynodesub.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment