Skip to content

Instantly share code, notes, and snippets.

@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'):
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]
from nose.tools import assert_equal
a = []
b = []
for i in xrange(1000):
a.append(i)
b.append(i)
a.append('a')
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 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()
"""
@nekoya
nekoya / private.xml
Created November 29, 2013 10:43
KeyRemap4MacBook custom XML
<?xml version="1.0"?>
<root>
<list>
<item>
<name>nekoya</name>
<list>
<item>
<name>ASCII Bracket mode</name>
<identifier>remap.nekoya_ascii_bracket_mode</identifier>
from datetime import datetime
import pytz
def dump(dt):
print '1. strftime : %s' % dt.strftime('%Y-%m-%d %H:%M')
print '2. str : %s' % dt
print '3. as utc : %s' % dt.astimezone(pytz.utc)
print '4. 3 as local : %s' % dt.astimezone(pytz.utc).astimezone(ny)
print ''
import calendar, pytz, time
from datetime import datetime
from benchmarker import Benchmarker
jst = pytz.timezone('Asia/Tokyo')
now_utc = datetime.now(pytz.utc)
now_jst = datetime.now(jst)
with Benchmarker(width=20, loop=10000) as bm:
for _ in bm('utc2utc'):
@nekoya
nekoya / toggle_flake8_e501.vim
Created April 30, 2013 10:52
vim-flake8でE501のチェックをトグルでON/OFF
function! Flake8IgnoreToggle()
let rule = 'E501'
if g:flake8_ignore == rule
echo 'flake8 check E501'
let g:flake8_ignore = ''
else
echo 'flake8 ignore E501'
let g:flake8_ignore = rule
endif
endfunction
@nekoya
nekoya / crypt_bench.py
Created March 5, 2013 07:22
Python benchmark (mcrypt, Crypto)
# -*- coding: utf-8 -*-
from benchmarker import Benchmarker
import base64
import mcrypt
from Crypto.Cipher import Blowfish
key = 'thisiskey'
iv = '123abc45'