Weblog

Thursday, 07 May 2009

  • save your cpu time

    Cpu is fast and disk is cheap. This is our mentality nowadays. But that can be wrong, and even it's true, it's still good to think about optimization.

    here's a simple benchmark of some operations: (if it's not aligned, not totally my fault:)

    CPU: Intel Pentium4 with HyperThreading dL1:16KB dL2:1024KB
    Benchmark         Time(ns)    CPU(ns) Iterations
    ------------------
    BM_FloatDivide          10         10  100000000
    BM_DoubleDivide         12         12  100000000
    BM_Tanf                 87         85  100000000
    BM_Tan                  99         99  100000000
    BM_Sinf                 54         54  100000000
    BM_Sin                  53         53  100000000
    BM_Cosf                 52         52  100000000
    BM_Cos                  59         59  100000000
    ....

    So, how to optimize those computationally-cost operations?
    1. Lookup Table is always a choice if you know the input range and the resolution.
    2. Taylor (or other) expansion is also a good choice
        Example:
        Tan(x) can be replaced by (1/(0.5-x) - 1/(x + 0.5))/pi : (with small difference:)
         Use gnuplot:
         gnuplot> plot [-0.499:0.499] tan((x)*pi), (1/(0.5-x) - 1/(x + 0.5))/pi

Monday, 14 July 2008

Tuesday, 08 April 2008

Thursday, 27 March 2008

  • Google Chat

    Do you use gmail? Do you use the chat gadget as well?

    If you do, you must have noticed that you can type emoticons in the small popup window, right?

    Now here're some small icons want you to try out, and let me know if you find more. (Please skip the space when you type the fourth in your chat)

    :(|)
    V.v.V
    \m/
    }: -)
    :{

  • Tricks in VI

    Have you ever consider to add new lines at some positions in VI?

    when I editting HTML w/ vi, found out that one of the file all the new lines are gone, and so, I want to add new lines after
    so I can see them clearly.

    This is how I do it in vi:

    :1,$ s/>/>^M/g

    ^M is to hold the ctrl-V and then press 'm'.

    Good luck!

Tuesday, 11 March 2008

Tuesday, 12 February 2008

  • Linux Command

    replace words in multiple files:
    for i in `ls *.txt`; do vi -c ":1,$ s/abc/abcd/g" $i; done
    But you have to close the file one by one. It might not be a bad thing because you might want to make sure the commands is correct anyway. The following method is the real "automation" if you can make sure your commands are correct.
    for i in `ls *.txt`; do vi -e -s tmp_cmds $i; echo $i; done
    and in the tmp_cmds, I put:
    :1,$ s/abc/abcd/g:wq!

    Another way is to do it with awk or curl:
    awk '{gsub("regexp", "sub"); print }' input_file > output_file
    counting:
    wc

    watch
    two windows:
    window A:
    for i in `seq 5 100`; do echo 1 > test.$i; sleep 10; done
    window B:
    watch -d ls

Friday, 01 February 2008

Thursday, 20 December 2007

  • ÄêÖÕ

    世界上最无聊的莫过于写blog这种事了。尤其是对一个天天和程序打交道的人来说。
    好了,写些流水账吧。
    今年有坏有好一整年,(废话,哪年不是啊?)
    好多个开始:工作,飞行...
    好多个结束:学业,在Santa Cruz的生活...
    LiangZhuo同志说,只要有那么两个,我就说好多好多。。。。特别夸张。keke.... 是啊是啊,我也发现了。好吧,多举几个例子吧:开始玩facebook, 结束天天上去看好友都在做什么。开始吃免费饭,开始讨厌吃免费饭。
    开始爱哭。开始爱笑。开始神经质~~~ hehe... (有这么说自己的吗?//kick bright)
    结束写故事,开始写流水账。
    不说了,饿了。

    祝大家新年快乐。圣诞好!