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

2008年3月6日木曜日

sakuraエディタのマクロ設定

やはりこういうのを使いこなさねばと思い。

設定->共通設定を選択
マクロタブを押し、マクロ一覧のディレクトリを
C:\Program Files\sakura\macro\
に設定し、
名前:URLエンコード ID:0 urlencode.js
名前:URL デコード ID:1 urldecode.js
と設定。

これにより、登録済みマクロから実行ができる。

ちなみに登録したマクロは下記二つ。

urldecode.js
//URLEncode.js
var oWsh = new ActiveXObject("WScript.Shell");
var sBuf;
sBuf = ExpandParameter("$C")
InsText(sBuf+"\n"+decodeURIComponent(sBuf));
//EOF




urlencode.js
//URLEncode.js
var oWsh = new ActiveXObject("WScript.Shell");
var sBuf;
sBuf = ExpandParameter("$C")
InsText(sBuf+"\n"+encodeURIComponent(sBuf));
//EOF

2008年2月24日日曜日

postgreSQLを入れてみる。

将来的にpythonでDB接続を目的として、PostgreSQLをインストールする。

1.管理用ユーザ[postgres]の作成
useradd -g users postgres

下記環境変数を設定する。
POSTGRES_HOME=/opt/local/postgresql
export PATH="$PATH":/opt/local/postgresql/bin
export PGLIB=$POSTGRES_HOME/lib
export PGDATA=$POSTGRES_HOME/data
export MANPATH=$POSTGRES_HOME/man
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH":"$PGLIB"

2.コンパイル
tar zxvf postgresql-8.2.5.tar.gz
cd postgresql-8.2.5
./configure --prefix=/opt/local/postgresql
make
su
make install


3.DB の作成
su - postgres
initdb

あとはプロセスを起動する。
postgres -D /opt/local/postgresql/data

2008年2月20日水曜日

prototype.js version1.6について

なんかすっごい遅くれていますが、prototype.js 1.6について調べてみました。

・Hashのインターフェースが変更
プロパティについては直接アクセスは禁止、set,get,usetメソッドを使用する。
new Hashによりオブジェクト生成が行えるようになった。
Hash.toQueryStringはObject.toQueryStringに代替するようになる。将来的に廃止するようです。
下記メソッドの削除:Hash.toJSON,Hash#remove
下記メソッドの追加:update,clone,toObject,get,set,unset

・Insertionクラスの非推奨
Element.insertを代用する
・Positionクラスの非推奨
Elemntクラスを使用する。

まぁ、こんな点を注意するべきだということです。
Ajaxあたりのクラスもざっくり変更あったのですが、あまり見てません。
わかり次第更新していこうかなぁ。

2008年1月24日木曜日

Yahoo! Media Player

Webページに埋め込まれているmp3を再生するjavascriptベースのmp3プレイヤー

http://developer.yahoo.com/mediaplayer/

これを使えばバンドのページでmp3を簡単に聞けるようになりそう。