Skip to content

Instantly share code, notes, and snippets.

from benchmarker import Benchmarker
import collections
with Benchmarker(width=40, loop=100000) as bm:
for _ in bm('empty dict'):
collections.Counter({})
for _ in bm('none'):
collections.Counter()
"""
from nose.tools import eq_, assert_equal
a = [1, 2, 3]
b = [1, 5, 3]
def test_eq():
eq_(a, b)
def test_assert_equal():
assert_equal(a, b)
from nose.tools import assert_equal
a = []
b = []
for i in xrange(1000):
a.append(i)
b.append(i)
a.append('a')
from benchmarker import Benchmarker
items = [1, 'foo', 'bar', 0, 0, 0]
with Benchmarker(width=40, loop=1000000) as bm:
for _ in bm('map'):
map(str, items)
for _ in bm('list'):
[str(x) for x in items]
@nekoya
nekoya / bench_list_copy.py
Created October 6, 2014 22:59
Python list copy benchmark
from benchmarker import Benchmarker
items = ['foo', 'bar', 'baz', 'hoge']
import copy
with Benchmarker(width=40, loop=100000) as bm:
for _ in bm('list'):
x = list(items)
for _ in bm('slice'):
# -*- coding: utf-8 -*-
import argparse
import re
import sys
from collections import namedtuple
import git
match_serial = re.compile(r'^\+\s+(\d{10})\s*; serial$').match
from benchmarker import Benchmarker
from itertools import ifilter
f = lambda x: x % 2
with Benchmarker(width=40, loop=1000) as bm:
for _ in bm('filter'):
list(filter(f, xrange(10000)))
for _ in bm('ifilter'):
list(ifilter(f, xrange(10000)))
from benchmarker import Benchmarker
import json
import ujson
imp_obj = {
'rectangle': {'tagid': '12345', 'banner': {'w': 300, 'h': 250}},
'big_banner': {'tagid': '22222', 'banner': {'w': 728, 'h': 90}},
'rectangle_with_inventory': {'tagid': '10000', 'banner': {'w': 300, 'h': 250}},
'banned': {'tagid': '54321', 'banner': {'w': 300, 'h': 250}},
}
import subprocess
import sys
import time
p = subprocess.Popen(
('redis-server', '--port', '6379', '--bind', '127.0.0.1'),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
WAIT = 0.001
@nekoya
nekoya / ssh-start
Created May 28, 2009 06:55
ssh-agent starter. exec ~/.ssh/agent-env on your screen.
!/bin/sh
ssh-agent | grep -v echo > "${HOME}/.ssh/agent-env"
. "${HOME}/.ssh/agent-env"
ssh-add
echo "please type:"
echo ". ~/.ssh/agent-env"