Skip to content

Instantly share code, notes, and snippets.

View benauthor's full-sized avatar

Evan Bender benauthor

View GitHub Profile
@benauthor
benauthor / profile_decorator.py
Created March 27, 2018 22:49
Python profiling decorator
from cProfile import Profile
from functools import wraps
import pstats
def profiled(f):
"""
Decorator for profiling a function
To use:
@benauthor
benauthor / unicode_safe_repr.py
Created May 10, 2018 19:07
python unicode-safe __repr__ pattern
# This is a pattern I like but I always forget the details
class Boo(object):
def __init__(self):
self.foo = u"☃"
def __unicode__(self):
return u"Boo(foo={})".format(self.foo)
def __str__(self):
@benauthor
benauthor / configured_spring_test.java
Last active July 11, 2018 13:44
Minimal spring-configured test setup
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = MyConfigurationClass.class)
public class MyTest {
@Autowired
private MyWhateverType myConfiguredBean;
@Test
public void testMyConfiguredBean() {
System.out.println("works");
@benauthor
benauthor / overhead.py
Last active August 27, 2018 20:34
Ballpark reference on function call, thread, process overhead
"""
Ballpark reference on function call, thread, process overhead
bender@dishoftheday:work$ python3 overhead.py 1000
forloop: 0.030994415283203125 ms
funcloop: 0.17786026000976562 ms
threadloop: 110.0301742553711 ms
threadloop2: 85.56795120239258 ms
threadloop_p: 77.57711410522461 ms
procloop: 5104.6202182769775 ms