2008年7月26日土曜日

python code reading宿題その1

python code reading の宿題

methodを実行する場合とmethodをローカル変数に代入してから実行する
場合の速度の違い
下記コードと実行結果。

結論:
100000回実行したところCPUtimeが110sec , 109secと1秒しか変わらない。
試行回数を増やしてみれば変わるかもしれないが、ほとんど変わらない様子。

////////////////////////////////////////////////////////
#!/usr/bin/python
from StringIO import StringIO
import profile

call_cnt=1000000
def callfunc():
strIO=StringIO()
write=strIO.write
for i in xrange(1,call_cnt):
write(str(i))

profile.run('callfunc()')

実行結果:
5000002 function calls in 109.890 CPU seconds

Ordered by: standard name

ncalls tottime percall cumtime percall filename:lineno(function)
999999 9.480 0.000 9.480 0.000 :0(append)
1000000 9.250 0.000 9.250 0.000 :0(isinstance)
1000000 8.040 0.000 8.040 0.000 :0(len)
1 0.010 0.010 0.010 0.010 :0(setprofile)
1 0.250 0.250 109.880 109.880 :1(?)
999999 52.030 0.000 85.690 0.000 StringIO.py:209(write)
999999 6.890 0.000 6.890 0.000 StringIO.py:38(_complain_ifclosed)
1 0.000 0.000 0.000 0.000 StringIO.py:54(__init__)
1 0.000 0.000 109.890 109.890 profile:0(callfunc())
0 0.000 0.000 profile:0(profiler)
1 23.940 23.940 109.630 109.630 sample_write.py:7(callfunc)



//////////////////////////////////////////////////////////////

#!/usr/bin/python
from StringIO import StringIO
import profile

call_cnt=1000000
def callmethod():
strIO=StringIO()
for i in xrange(1,call_cnt):
strIO.write( str(i))

profile.run('callmethod()')


実行結果:
5000002 function calls in 110.210 CPU seconds

Ordered by: standard name

ncalls tottime percall cumtime percall filename:lineno(function)
999999 7.710 0.000 7.710 0.000 :0(append)
1000000 9.580 0.000 9.580 0.000 :0(isinstance)
1000000 7.600 0.000 7.600 0.000 :0(len)
1 0.000 0.000 0.000 0.000 :0(setprofile)
1 0.260 0.260 110.210 110.210 :1(?)
999999 50.450 0.000 82.330 0.000 StringIO.py:209(write)
999999 6.990 0.000 6.990 0.000 StringIO.py:38(_complain_ifclosed)
1 0.000 0.000 0.000 0.000 StringIO.py:54(__init__)
1 0.000 0.000 110.210 110.210 profile:0(callmethod())
0 0.000 0.000 profile:0(profiler)
1 27.620 27.620 109.950 109.950 sample_strio_write.py:6(callmethod)

2008年7月21日月曜日

EeePCを買う

EeePC901を購入。
そして16GBのSDHCを購入。

SDHCはFATなので、NTFSにしたいため下記コマンドを実行

>convert e: /fs:ntfs

これにて2GB以上のファイルも扱えるようになる。

2008年7月3日木曜日

sakuraの入力補完&キーワードヘルプ

とりあえず設定したので覚書程度に


設定->タイプ別設定->支援->入力補完機能
入力補完対象の文字を記述したファイルを設定
////////以下設定例/////////
import
def
class

//////////////////////////
入力補完を行うときにはCtrl+/をタイプすると入力候補が表示される。

設定->タイプ別設定->支援->キーワードヘルプ機能
キーワード設定するファイルを設定
////////以下設定例/////////
ほげ /// ヘルプ情報

//////////////////////////

キーワードヘルプは範囲選択すると表示される。


これでpythonのクラスをさらってきて、入力補完にすると
使いやすくはなるのかもしれませんね。
入力補完のリストは時間がないので、後日作る予定。