Skip to content

Instantly share code, notes, and snippets.

View bhavishyagopesh's full-sized avatar

BHAVISHYA bhavishyagopesh

View GitHub Profile
@bhavishyagopesh
bhavishyagopesh / frontendDevlopmentBookmarks.md
Created April 23, 2017 20:44 — forked from dypsilon/frontendDevlopmentBookmarks.md
A badass list of frontend development resources I collected over time.
@bhavishyagopesh
bhavishyagopesh / pylifecycle.c
Created July 21, 2017 03:41
_Py_InitializeMainInterpreter Definition
/* Update interpreter state based on supplied configuration settings
*
* After calling this function, most of the restrictions on the interpreter
* are lifted. The only remaining incomplete settings are those related
* to the main module (sys.argv[0], __main__ metadata)
*
* Calling this when the interpreter is not initializing, is already
* initialized or without a valid current thread state is a fatal error.
* Other errors should be reported as normal Python exceptions with a
* non-zero return code.
@bhavishyagopesh
bhavishyagopesh / pythonrun.c
Created July 21, 2017 05:21
Py_InitializeEx Definition
void
Py_InitializeEx(int install_sigs)
{
PyInterpreterState *interp;
PyThreadState *tstate;
PyObject *bimod, *sysmod;
char *p;
char *icodeset = NULL; /* On Windows, input codeset may theoretically
differ from output codeset. */
char *codeset = NULL;
@bhavishyagopesh
bhavishyagopesh / python
Created July 21, 2017 05:24
run_mod definition
static PyObject *
run_mod(mod_ty mod, const char *filename, PyObject *globals, PyObject *locals,
PyCompilerFlags *flags, PyArena *arena)
{
PyCodeObject *co;
PyObject *v;
co = PyAST_Compile(mod, filename, flags, arena);
if (co == NULL)
return NULL;
v = PyEval_EvalCode(co, globals, locals);
static PyObject *
run_mod(mod_ty mod, PyObject *filename, PyObject *globals, PyObject *locals,
PyCompilerFlags *flags, PyArena *arena)
{
PyCodeObject *co;
PyObject *v;
co = PyAST_CompileObject(mod, filename, flags, -1, arena);
if (co == NULL)
return NULL;
v = PyEval_EvalCode((PyObject*)co, globals, locals);
@bhavishyagopesh
bhavishyagopesh / bm_threading.py
Last active August 10, 2017 22:32
Benchmark threading module.
"""
Benchmark threading module.
"""
# FIXME : notify hangs
import perf
from six.moves import xrange
import threading
@bhavishyagopesh
bhavishyagopesh / bm_concurrent.py
Last active August 11, 2017 23:07
Benchmark concurrency.
"""
Benchmark concurrency.
"""
import perf
from six.moves import xrange
import threading
import multiprocessing
def add_cmdline_args(cmd, args):
The above script tries to benchmark "Concurrency" implemented using threading and multiprocessing.Actually "threads" in cpython are restricted by "GIL"
,so it's not actually concurrent...On the other hand "multiprocessing" module creates whole different processes but there is substaintial cost involved in
spawing a whole new process.
So the there is a trade-off involved which is evident as we increase "CRUNCH_NO" variable.
But the benchmark actually tries to compare the same phenomenon in py2 and py3.And py2 looks faster here.
I'm adding two graphs comparing the timings for py2 and py3.
@bhavishyagopesh
bhavishyagopesh / bm_number_crunching.py
Created August 12, 2017 00:32
To check the effect for int vs Long
import perf
from six.moves import xrange
def add_cmdline_args(cmd, args):
if args.benchmark:
cmd.append(args.benchmark)
CRUNCH_NO=10000000
def bench_number_crunching(loops):
range_it = xrange(loops)
t0 = perf.perf_counter()
@bhavishyagopesh
bhavishyagopesh / bm_zlib.py
Last active August 16, 2017 11:29
Benchmark zlib module.
"""
Benchmark zlib module.
"""
import perf
from six.moves import xrange
import zlib
import binascii