English 中文(简体)
我的IO如何在埃尔兰缓慢运行?
原标题:How come my IO runs so slowly in Erlang?

I m读512^2白色空间,在我的埃尔兰方案的一份文本档案中写了两字,把两字推到 st。

在埃尔兰,这占用了2m25s,相当于Haskell方案,它耗资3,因此,我必须反对埃尔兰以某种方式这样做。

Am I using Erlang s IO primitives in a stupid way, or is there something else wrong with my program?

请注意,我不关心由此产生的清单中的价值顺序,因此没有发生逆转。

Erlang:

-module(iotest).

-import(io).

-export([main/0]).

main() ->
    Values = read(),
    io:write(Values).

read() -> read([]).

read(Acc) ->
    case io:fread("", "~f") of
        {ok, Value} -> read([Value | Acc]);
        eof -> Acc
    end.

Haskell:

module IOTest (
    main
) where

main :: IO ()

main = do
    text <- getContents
    let values = map read (words text) :: [Double]
    putStrLn $ show values
    return ()

非常感谢任何帮助。

最佳回答

无,你不停地使用Erlang IO。 这个问题与Erlang IO有关,众所周知,这一问题并不迅速。 埃尔兰被广泛用于写作服务器,因此,光彩的、面向的IO被很好地调整。 面向行业的档案并非非常糟糕,而是使用奥格模块从事 st的工作。 埃尔兰并未广泛用于此类工作。 如果你需要这种行动,你应例行写出自己的专门投入。 你有两种选择:

  1. use io for reading from file in raw and binary mode and then split input using binary module and then use list_to_float/1 for conversion.
  2. use specialized port oriented stdin reading routine (as you can see for example in http://shootout.alioth.debian.org/u64q/program.php?test=regexdna&lang=hipe&id=7 note read/0 function and -noshell -noinput parameters for vm invocation) and then continue as in first option.

在地雷问题上(以及从以往的地雷经验来看),对你来说,最大的影响是,利用像扫描一样的例行投入,对以缓慢的(重复的)休战为推导的浮动脱硫,但需要一些非对地貌加以证明。

问题回答

暂无回答




相关问题
Euler Problem in Haskell -- Can Someone Spot My Error

I m trying my hand at Euler Problem 4 in Haskell. It asks for that largest palindrome formed by multiplying two three-digit numbers. The problem was simple enough, and I thought my Haskell-fu was up ...

How does foldr work?

Can anybody explain how does foldr work? Take these examples: Prelude> foldr (-) 54 [10, 11] 53 Prelude> foldr (x y -> (x+y)/2) 54 [12, 4, 10, 6] 12.0 I am confused about these executions....

Efficient queue in Haskell

How can I efficiently implement a list data structure where I can have 2 views to the head and end of the list, that always point to a head a tail of a list without expensive calls to reverse. i.e: ...

Problem detecting cyclic numbers in Haskell

I am doing problem 61 at project Euler and came up with the following code (to test the case they give): p3 n = n*(n+1) `div` 2 p4 n = n*n p5 n = n*(3*n -1) `div` 2 p6 n = n*(2*n -1) p7 n = n*(5*n -3)...

Ways to get the middle of a list in Haskell?

I ve just started learning about Functional Programming, using Haskel. I m slowly getting through Erik Meijer s lectures on Channel 9 (I ve watched the first 4 so far) and in the 4th video Erik ...

haskell grouping problem

group :: Ord a => [(a, [b])] -> [(a, [b])] I want to look up all pairs that have the same fst, and merge them, by appending all the list of bs together where they have the same a and discarding ...

Closest equivalent to subprocess.communicate in Haskell

I want to do a popen() / python s subprocess.communicate from Haskell - start a program, give it stdin, and get its stdout/stderr. What s the most direct / Haskellish way to do this?

热门标签