- 浏览: 37564 次
- 来自: 深圳
文章分类
最新评论
-
ZacMa:
哈哈,突然感觉里面没怎么介绍,全是贴代码了
<8>redis及erl-redis阅读 -
惊涛翻案:
马博士,给我开课吧
<8>redis及erl-redis阅读
1
Deep and flat lists
lists:flatten的代价非常高,甚至比 ++的代价更高,所以要尽可能避免使用,
可以有几种方法避免,
(1), 发送list到一个port时候,ports可以解析深度lists, 因此不用转化,传入深度list即可
(2)一些bif可以支持深度list,例如 list_to_binary/1 or iolist_to_binary/1 也是支持深度list
(3)如果list是仅仅1层,可以用lists:append代替, 原文
lists:flatten/1 builds an entirely new list. Therefore, it is expensive, and even more expensive than the ++ (which copies its left argument, but not its right argument).
In the following situations, you can easily avoid calling lists:flatten/1:
When sending data to a port. Ports understand deep lists so there is no reason to flatten the list before sending it to the port.
When calling BIFs that accept deep lists, such as list_to_binary/1 or iolist_to_binary/1.
When you know that your list is only one level deep, you can can use lists:append/1.
Port example
DO
...
port_command(Port, DeepList)
...
DO NOT
...
port_command(Port, lists:flatten(DeepList))
...
Append example
DO
> lists:append([[1], [2], [3]]).
[1,2,3]
>
DO NOT
> lists:flatten([[1], [2], [3]]).
[1,2,3]
>
2
递归和尾递归在性能上区别不是很大,不过递归要比尾递归浪费更多空间,并且空间的大小和列表的长短是成比例的
In the performance myth chapter, the following myth was exposed: Tail-recursive functions are MUCH faster than recursive functions.
To summarize, in R12B there is usually not much difference between a body-recursive list function and tail-recursive function that reverses the list at the end. Therefore, concentrate on writing beautiful code and forget about the performance of your list functions. In the time-critical parts of your code (and only there), measure before rewriting your code.
Important note: This section talks about lists functions that construct lists. A tail-recursive function that does not construct a list runs in constant space, while the corresponding body-recursive function uses stack space proportional to the length of the list. For instance, a function that sums a list of integers, should not be written like this
Deep and flat lists
lists:flatten的代价非常高,甚至比 ++的代价更高,所以要尽可能避免使用,
可以有几种方法避免,
(1), 发送list到一个port时候,ports可以解析深度lists, 因此不用转化,传入深度list即可
(2)一些bif可以支持深度list,例如 list_to_binary/1 or iolist_to_binary/1 也是支持深度list
(3)如果list是仅仅1层,可以用lists:append代替, 原文
lists:flatten/1 builds an entirely new list. Therefore, it is expensive, and even more expensive than the ++ (which copies its left argument, but not its right argument).
In the following situations, you can easily avoid calling lists:flatten/1:
When sending data to a port. Ports understand deep lists so there is no reason to flatten the list before sending it to the port.
When calling BIFs that accept deep lists, such as list_to_binary/1 or iolist_to_binary/1.
When you know that your list is only one level deep, you can can use lists:append/1.
Port example
DO
...
port_command(Port, DeepList)
...
DO NOT
...
port_command(Port, lists:flatten(DeepList))
...
Append example
DO
> lists:append([[1], [2], [3]]).
[1,2,3]
>
DO NOT
> lists:flatten([[1], [2], [3]]).
[1,2,3]
>
2
递归和尾递归在性能上区别不是很大,不过递归要比尾递归浪费更多空间,并且空间的大小和列表的长短是成比例的
In the performance myth chapter, the following myth was exposed: Tail-recursive functions are MUCH faster than recursive functions.
To summarize, in R12B there is usually not much difference between a body-recursive list function and tail-recursive function that reverses the list at the end. Therefore, concentrate on writing beautiful code and forget about the performance of your list functions. In the time-critical parts of your code (and only there), measure before rewriting your code.
Important note: This section talks about lists functions that construct lists. A tail-recursive function that does not construct a list runs in constant space, while the corresponding body-recursive function uses stack space proportional to the length of the list. For instance, a function that sums a list of integers, should not be written like this
发表评论
-
erlang版本安装相关问题 <32>
2014-05-10 15:54 581<1> erlang R1603安装后,crytp ... -
关于iolist<30>
2014-01-15 10:42 586iolist是比较常用的数据结构. iolist的 ... -
erlang 字符编码 <29>
2014-01-14 16:31 1228用mochiweb通过网页发送中文到服务器,结果服务器显示乱码 ... -
<27>erlang record
2013-11-19 11:19 738平时总是忘记record的某些使用方法,每次使用都要翻文档, ... -
<26>io:format io_lib:format
2013-11-14 11:07 1277使用io_lib时候要注意参数,尤其是封装json串的时候,否 ... -
<24>用error_logger间隔记录日志
2013-10-22 16:09 628执行下面的代码 test:start(). test.erl ... -
<23>erlang 数据存储
2013-10-15 22:15 1623做为后端开发者,经常 ... -
<22> erlang中的数学计算函数相关
2013-10-10 10:34 15951. 幂函数 match:pow(m,n) 表示m的n次幂 ... -
<20>erlang中的类型和函数说明
2013-09-15 11:25 936erlang是一种动态类型的语言(运行时才决定数据类型),可以 ... -
<19>erlang中的时间,日期
2013-09-06 11:21 1163时间函数涉及的数据类型: DATA TYPES datetim ... -
<17>Efficiency Guide之Function
2013-08-27 22:30 5491. 函数模式匹配 模式匹配,在函数头,case和receiv ... -
<16>Efficiency Guide之Common Caveats
2013-08-11 11:07 767(1) ++ 如果做一个list的反转,不要这样, naiv ... -
<15> lists模块补充
2013-08-05 20:12 799%% 对list模块经常用到的进行补充 %% 1 对所有元素进 ... -
<15> lists模块解析和补充
2013-07-24 17:57 12%% 对list模块经常用到的进行补充 %% 1 对所有元素 ... -
<12>简述erlang的几种错误
2013-04-14 23:31 11541) badarg Bad argument. The ar ... -
<11>erlang中方便使用的模块和命令(2)
2013-04-06 22:33 757(1) 进程字典到底用不用,很多人推荐使用 http:// ... -
<9>rabbitmq网络层
2013-01-31 00:20 726抽离出了网络层, 逻辑层待以后研究 https://gith ... -
<8>redis及erl-redis阅读
2013-01-16 10:14 8191 redis的功能相当的强大,里面的发布订阅pub/su ... -
<7>pg2 分析
2012-12-08 13:42 1227网上看到erlang的pg2模块似乎没人推荐使用,但是还是有不 ... -
<6>error_logger 使用
2012-12-02 16:24 1428erlang中日志管理主要有error_loggger 模块, ...
相关推荐
Optimizing IO <br> Efficient Screen Output <br> Efficient Binary File IO <br> Efficient Text File IO <br> Summary <br> <br> Chapter 13. Optimizing Your Code Further <br> Arithmetic Operations <br> ...
Compensated Predictive Coding<br>3.6 Information-Preserving Differential Coding<br>3.7 Summary <br>3.8 Exercises<br>References<br>Chapter 4 Transform Coding<br>4.1 Introduction<br>4.1.1 Hotelling ...
UniString.zip<br>Class to manipulate UNICODE string on Window 95/98.(6KB)<END><br>11,faststring.zip<br>Fast and efficient CString replacement(63KB)<END><br>12,StdString.zip<br>CString like class using...
Y Direct Addressing Capability 1 MByte<br>of Memory<br>Y Architecture Designed for Powerful<br>Assembly Language and Efficient High<br>Level Languages<br>Y 14 Word, by 16-Bit Register Set with<br>...
mpeg2encode / mpeg2decode<br> =========================<br> MPEG-2 Encoder / Decoder, Version 1.2, July 19, 1996<br><br> Copyright (c) 1996 <br> MPEG Software Simulation Group<br><br> E-mail: mssg@...
<br><br>Fourier Analysis on Finite Groups with Applications in Signal Processing and System Design <br><br>信号处理和系统分析中有限群的傅立叶分析和应用<br><br>by Radomir S. Stankovic , Claudio Moraga ...
For exporters seeking<br>efficient links in their supply chains, China is frequently the price setter and an<br>unrivalled source of cost advantage.<br>Both of these trends stand out in the ...
<br>Network+ Exam Cram 2 ,Second Edition <br><br>Exam Cram N10-003<br><br>By Drew Bird, Mike Harwood <br> <br>Publisher: Que <br>Pub Date: June 08, 2005 <br>ISBN: 0-7897-3254-8 <br>Pages: 528 <br> <br...
Overview The book has a strong focus on efficient methods for finite field arithmetic<br>(Chapter 2) and elliptic curve arithmetic (Chapter 3). Next, Chapter 4 surveys the<br>known attacks on the ...
<br>CISA Exam Cram: Certified Information Systems Auditor (Exam Cram 2)<br><br>by Allen Keele , Keith Mortier <br><br><br>Paperback: 456 pages <br>Publisher: Que (April 30, 2005) <br>Language: English...
defragmentation technology provides fast, efficient and complete defragmentation of even your largest drives with minimal system resource usage.<br><br>PerfectDisk's Command Center provides powerful ...
You'll also <br> learn best practices that ensure your code will be efficient, reusable, <br> and robust. Why spend months or years discovering the best ways to <br> design and code C# when this book...
2004 <br>ISBN : 1-58720-118-6 <br>Pages : 264 <br> <br> <br><br><br><br>Understand the business case for storage networks and lower your total cost of ownership with this comprehensive guide<br><br>...
Studying the more efficient of these facilities enabled us to<br>compile a set of “best-practice” technologies for energy efficiency. These best practices include:<br>improved air management, ...
<br><br>The ARM and Thumb C compilers are mature, industrial-strength ANSI C compilers which<br>are capable of producing high quality machine code. However, when writing source code,<br>it is always ...
A large number of research efforts have appeared in literature aimed at<br>effective modelling of spatial data and efficient processing of spatial queries.<br>This book investigates several aspects ...
Preface v<br>1 Motivation 1<br>1.1 WhyWeWrote This Book . . . . . . . . . . . . . . . . . . . 1<br>1.2 ForWhomWe AreWriting . . . . . . . . . . . . . . . . . . 2<br>1.2.1 Those Accustomed to Fortran ...
™ Pro<br> <br> <br> <br>Powerful. Efficient. Fast.<br><br>Today, software consumers demand more than ever before from developers. The pressure to deliver more features with higher quality in less ...
Book Description<br><br>Comprehensive Real-World Guidance for Every Embedded Developer and Engineer<br><br>This book brings together indispensable knowledge for building efficient, high-value, Linux-...