Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Hack to test speed of launching a sub process in node.js or python
#!/bin/bash
#####
# Launch and time python and node scripts that also launch subprocesses
echo start launch python data subprocess...
date "+%T %s %N"
python mypydatesub.py
echo
echo start launch python compiled data subprocess...
date "+%T %s %N"
python mypydatesub.pyc
echo
# make sure you have installed nvm see https://github.com/creationix/nvm#install-script
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # 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 launch.sh
# now the python script
# mypydatesub.py
import subprocess
subprocess.call(["date", '+%T %s %N'])
subprocess.call(["date", '+%T %s %N'])
# end of mypydatesub.py
# 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("mypydatesub.py")
>>> 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