Skip to content

Instantly share code, notes, and snippets.

@MOON-CLJ
MOON-CLJ / ipython_test
Last active December 13, 2015 19:49
ipython map,list comprehensions,与python自带的map对比的性能测试
在macbook pro 4核上的测试结果,python自带的map表现比起ipython 的map,list comprehensions都要好。但是有优化的multi_mcpi还是不错。
$ ipcluster start --n=4
print mcpi(100000000)
#print multi_mcpi_by_map(dview, 100000000) # 传递太耗时
#print multi_mcpi_by_list_comp(dview, 100000000)
#print multi_mcpi(dview, 100000000)
$ time py multi_mcpi.py
importing random from random on engine(s)
#!/usr/bin/python
__doc__ = """Tiny HTTP Proxy.
This module implements GET, HEAD, POST, PUT and DELETE methods
on BaseHTTPServer, and behaves as an HTTP proxy. The CONNECT
method is also implemented experimentally, but has not been
tested yet.
Any help will be greatly appreciated. SUZUKI Hisao
@MOON-CLJ
MOON-CLJ / decorator.py
Last active December 14, 2015 16:19
some python usage snippet
3,
def timeit(method):
def timed(*args, **kw):
ts = time()
result = method(*args, **kw)
te = time()
logging.info('%r %2.2f sec' % (method.__name__, te-ts))
return result
return timed
@MOON-CLJ
MOON-CLJ / gist:5213953
Last active December 15, 2015 06:09
text xapian_weibo index performance
index_text用法 replace
[2013-03-21 22:44:49] folder[_hehe_2011-08-21] num indexed: 350000
[2013-03-21 22:44:57] folder[_hehe_2010-12-14] num indexed: 360000
[2013-03-21 22:45:05] folder[_hehe_2010-12-14] num indexed: 370000
[2013-03-21 22:45:11] folder[_hehe_2010-04-08] num indexed: 380000
[2013-03-21 22:45:17] folder[_hehe_2010-10-25] num indexed: 390000
[2013-03-21 22:45:25] folder[_hehe_2011-07-02] num indexed: 400000
[2013-03-21 22:45:34] folder[_hehe_2011-10-10] num indexed: 410000
[2013-03-21 22:45:43] folder[_hehe_2011-02-02] num indexed: 420000
[2013-03-21 22:45:51] folder[_hehe_2011-02-02] num indexed: 430000
@MOON-CLJ
MOON-CLJ / tokudb_install
Last active December 18, 2015 07:29
install tokudb
~/.bashrc
alias gcc='/usr/local/bin/gcc'
export CC=/usr/local/bin/gcc
export CXX=/usr/local/bin/g++
CFLAGS="-O3 -g -fno-exceptions -static-libgcc -fno-omit-frame-pointer -fno-strict-aliasing"
CXXFLAGS="-O3 -g -fno-exceptions -fno-rtti -static-libgcc -fno-omit-frame-pointer -fno-strict-aliasing"
export CFLAGS CXXFLAGS
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/scws/lib/:/home/arthas/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/sbin
export LIBRARY_PATH=/usr/lib/x86_64-linux-gnu
export PATH=$PATH:/usr/local/tokutek/mysql/bin/
@MOON-CLJ
MOON-CLJ / gist:6019306
Last active December 19, 2015 21:19
name mangling in python
In [29]: class foo():
....: def __init__(self):
....: self.__x = 1
....:
In [30]: r1 = foo()
In [31]: r1.__x
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
@MOON-CLJ
MOON-CLJ / gist:6028017
Last active December 19, 2015 22:29
python Lookup instance attribute
In [88]: class C:
....: def foo(self):
....: pass
....: foo = classmethod(foo)
....:
In [89]: C.__dict__
Out[89]:
{'__doc__': None,
'__module__': '__main__',
@MOON-CLJ
MOON-CLJ / iter_all_docs_1_2.diff
Last active December 28, 2015 21:29
无cache与有cache 区别不大
--- 1.txt 2013-11-20 21:24:35.000000000 +0800
+++ 2.txt 2013-11-20 21:24:35.000000000 +0800
@@ -1,4 +1,4 @@
- 309378992 function calls in 596.173 seconds
+ 309378992 function calls in 592.411 seconds
Ordered by: standard name
@@ -89,13 +89,13 @@
1 0.000 0.000 0.000 0.000 __init__.py:705(NetworkError)
@MOON-CLJ
MOON-CLJ / iter_all_docs_1_3.diff
Last active December 28, 2015 21:29
本地database直接访问vs本地database tcp访问
--- 1.txt 2013-11-20 21:24:35.000000000 +0800
+++ 3.txt 2013-11-20 21:24:35.000000000 +0800
@@ -1,4 +1,4 @@
- 309378992 function calls in 596.173 seconds
+ 309378996 function calls in 9818.898 seconds
Ordered by: standard name
@@ -33,7 +33,7 @@
1 0.000 0.000 0.000 0.000 __init__.py:2732(ExpandDecider)
@MOON-CLJ
MOON-CLJ / search_3_4.diff
Last active December 29, 2015 12:49
本地database直接访问 有cache和没cache(100万,大于10s的差异才被保留)
- 141990135 function calls in 4517.825 seconds
+ 141990135 function calls in 305.731 seconds
- 15732127 35.384 0.000 41.229 0.000 __init__.py:6549(__init__)
+ 15732127 27.876 0.000 32.483 0.000 __init__.py:6549(__init__)
class TermListItem(object):
def __init__(self, iter, term):
self._iter = iter
self.term = term
self._wdf = None