Skip to content

Instantly share code, notes, and snippets.

@odedlaz
odedlaz / compiled_print_func_snippet.py
Created December 6, 2016 08:59
compiled_print_func_snippet.py
__keywords = {}
__keywords[GENERATED_NAME] = STATEMENT
__keywords[ANOTHER_GENERATED_NAME] = ANOTHER_STATEMENT
@odedlaz
odedlaz / optimzed_compile_print.py
Last active December 6, 2016 10:13
optimzed_compile_print.py
import os
import six
from time import time
from random import choice
from string import Formatter
from string import ascii_letters
from inspect import currentframe
string_formatter = Formatter()
@odedlaz
odedlaz / compiled_exec_print.py
Last active December 6, 2016 09:47
compiled_exec_print.py
from __future__ import print_function
import os
import sys
import six
from time import time
from random import choice
from string import Formatter
from string import ascii_letters
from inspect import currentframe
@odedlaz
odedlaz / exec_print.py
Last active December 6, 2016 09:47
exec_print.py
from __future__ import print_function
import os
import sys
import six
from time import time
from random import choice
from string import Formatter
from string import ascii_letters
from inspect import currentframe
@odedlaz
odedlaz / eval_print.py
Last active December 6, 2016 09:46
eval_print.py
import os
import six
from time import time
from inspect import currentframe
from string import Formatter
string_formatter = Formatter()
devnull = open(os.devnull, 'w')
@odedlaz
odedlaz / std_print.py
Created December 5, 2016 08:12
std_print.py
from time import time
import os
devnull = open(os.devnull, 'w')
name = "oded"
t = time()
for _ in range(50000):
print("my name is {} & 2*3={}".format(name, 2*3),
file=devnull)
@odedlaz
odedlaz / _PyBytes_Resize.c
Created December 1, 2016 10:30
_PyBytes_Resize
/* The following function breaks the notion that bytes are immutable:
it changes the size of a bytes object. We get away with this only if there
is only one module referencing the object. You can also think of it
as creating a new bytes object and destroying the old one, only
more efficiently. In any case, don't use this if the bytes object may
already be known to some other part of the code...
Note that if there's not enough memory to resize the bytes object, the
original bytes object at *pv is deallocated, *pv is set to NULL, an "out of
memory" exception is set, and -1 is returned. Else (on success) 0 is
returned, and the value in *pv may or may not be the same as on input.
@odedlaz
odedlaz / PyBytes_Concat.c
Created December 1, 2016 10:22
PyBytes_Concat
void
PyBytes_Concat(PyObject **pv, PyObject *w)
{
assert(pv != NULL);
if (*pv == NULL)
return;
if (w == NULL) {
Py_CLEAR(*pv);
return;
}
from __future__ import print_function
import os
import sys
# look at timeit.py gist
# https://gist.github.com/odedlaz/7811f703cc30a9d266817eaa4014ba7a
from random import randint
from timeit import TimeIt
from six.moves import range, cStringIO
from __future__ import print_function
import gc
import sys
import time
class TimeIt(object):
def __init__(self, scope_name="", fd=sys.stdout):
self._start = None
self._fd = fd