Re: [shlug] 问一个haskell读文件效率问题

6 views
Skip to first unread message
Message has been deleted

yi lu

unread,
Jan 26, 2014, 8:35:22 AM1/26/14
to sh...@googlegroups.com
问了好多遍的样子


On Sun, Jan 26, 2014 at 10:10 AM, Yuankuns Shi <shiyuan...@gmail.com> wrote:
最近用haskell处理一个1.7G的文本文件,就是简单的split&join输出。haskell编译成二进制码以后的,居然要4分钟,而相应的python只花了50秒。这个问题有人碰到过吗?
haskell代码
import System.IO
import Control.Monad
import Data.List
import Data.List.Split
main=do
    handle<-openFile "20131008.test" ReadMode
    contents<-hGetContents handle
    let result= process contents
        write result
    hClose handle
write :: [Char] -> IO ()
write output=do
    h<-openFile "20131008.csv" WriteMode
    hPutStr h output
    hClose h
process istr=intercalate "\n" (map rep_spt (lines istr))
rep_spt istr=intercalate ";" (splitOn "," istr)
python
import string
f_r=file('20131008.test','r')
a=f_r.readlines()
result=[]
for i in a:
    result.append(string.join(i.split(','),';'))
f_w=file('20131008.csv','w')
f_w.writelines(result)

--
-- You received this message because you are subscribed to the Google Groups Shanghai Linux User Group group. To post to this group, send email to sh...@googlegroups.com. To unsubscribe from this group, send email to shlug+un...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/shlug?hl=zh-CN
---
您收到此邮件是因为您订阅了 Google 网上论坛的“Shanghai Linux User Group”论坛。
要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到 shlug+un...@googlegroups.com
要查看更多选项,请访问 https://groups.google.com/groups/opt_out。

Reply all
Reply to author
Forward
0 new messages