当前位置:首页 > 开发 > 编程语言 > 编程 > 正文

The Eight Myths of Erlang Performance

发表于: 2011-12-01   作者:bookjovi   来源:转载   浏览:
摘要: erlang有一篇guide很有意思: http://www.erlang.org/doc/efficiency_guide 里面有个The Eight Myths of Erlang Performance: http://www.erlang.org/doc/efficiency_guide/myths.html   Myth: Funs are sl

erlang有一篇guide很有意思: http://www.erlang.org/doc/efficiency_guide

里面有个The Eight Myths of Erlang Performance: http://www.erlang.org/doc/efficiency_guide/myths.html

 

Myth: Funs are slow

Myth: List comprehensions are slow

Myth: Tail-recursive functions are MUCH faster than recursive functions

Myth: '++' is always bad

Myth: Strings are slow

Myth: Repairing a Dets file is very slow

Myth: BEAM is a stack-based byte-code virtual machine (and therefore slow)

Myth: Use '_' to speed up your program when a variable is not used

 

另一篇文章http://www.erlang.org/doc/efficiency_guide/listHandling.html#id209936

里面提到了List comprehensions的实现,List comprehensions在erlang中被compiler转换成fun,如下:

[Expr(E) || E <- List]

将会被compile成下面的fun

'lc^0'([E|Tail], Expr) ->
    [Expr(E)|'lc^0'(Tail, Expr)];
'lc^0'([], _Expr) -> [].

 

里面有提到了另一种转化形式:

[io:put_chars(E) || E <- List]

'lc^0'([E|Tail], Expr) ->
    Expr(E),
    'lc^0'(Tail, Expr);
'lc^0'([], _Expr) -> [].
 因为此种情况下compiler可以知道List comprehensions的结果没有被使用,所以直接优化成尾递归。

 

The Eight Myths of Erlang Performance

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号