Skip to content

Instantly share code, notes, and snippets.

@karlroberts
Created March 15, 2017 01:45
Show Gist options
  • Save karlroberts/141e1e7b38ca85ac3da7b88297d48a97 to your computer and use it in GitHub Desktop.
Save karlroberts/141e1e7b38ca85ac3da7b88297d48a97 to your computer and use it in GitHub Desktop.
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