|
|
| Author |
Message |
< Erlang ~ a question on style and efficiency |
| paolo |
Posted: Mon Apr 25, 2011 7:02 pm |
|
|
|
User
Joined: 03 Jun 2010
Posts: 11
|
hi all,
I am writing a module which will provide some functionalities, one of these will be compression (zlib, deflate, or no one) of a binary.
In your opinion which of these two functions is the best one in terms of efficiency/speed and style?
Code:
compress(gzip, Bin) ->
zlib:gzip(Bin);
compress(deflate, Bin) ->
zlib:compress(Bin);
compress(none, Bin) ->
Bin.
encode(Method, Bin) ->
case Method of
none ->
Bin;
gzip ->
zlib:gzip(Bin);
deflate ->
zlib:compress(Bin)
end.
Thanks in advance
p |
|
|
| Back to top |
|
| rvirding |
Posted: Thu Apr 28, 2011 10:15 am |
|
|
|
User
Joined: 30 Aug 2006
Posts: 452
Location: Stockholm, Sweden
|
In terms of style I would say the first function compress/2 is better, it feels more Erlangy, though there is nothing directly wrong with encode/2.
In terms of efficiency and speed they are exactly the same, in fact the compiler will transform both to the same code. The same pattern matching algorithm is used for all pattern matching, whether it is in function clauses, a case or a receive. In this case it really doesn't matter as most of the work will be in the encoding. |
_________________ Robert Virding, Erlang Solutions Ltd. |
|
| Back to top |
|
| paolo |
Posted: Thu Apr 28, 2011 3:23 pm |
|
|
|
User
Joined: 03 Jun 2010
Posts: 11
|
thanks indeed, this was the answer i was looking for  |
|
|
| Back to top |
|
| raymondb |
Posted: Thu Jun 09, 2011 3:45 am |
|
|
|
Joined: 08 Jun 2011
Posts: 4
|
I reckon that most would choose the first function compress to be better as it follows the form and gives the Erlang feel more to it. I am not saying that the second one has something wrong as it is just a choice to go with the first one.
With efficiency, I would have to say that they perform the same and it will even be parsed to the same machine code. |
|
|
| Back to top |
|
| dongdongwu |
Posted: Thu Sep 20, 2012 6:00 am |
|
|
|
User
Joined: 19 Sep 2012
Posts: 236
|
His good friend Diane said: "Christian Louboutin Men Shoes was a magician, he make shoes is immediately put his female people with legs and advantage. He understands women wanted to do and can make them into beautiful Cinderella." Madonna often in its concert wearing Christian louboutin high heels , and some famous superstar like Angelina jolie, mariah Carey, beyonce Knowles, the famous Japanese singer YaYouMei Hamasaki helps Christian Louboutin Men Shoes set up its powerful position. The youngest customers will count Tom cruise's daughter sully cruz. Louboutin made for only a pair of handmade Christian Louboutin high heel Shoes! Want to be more fashion? Put on Christian Louboutin Outlet !
Candy colors of the chalaza high-heeled shoes with lolita type allure, set full finely gem blue "neon shoes" is to need to use "sexy" to describe. Each pair are worth careful appreciation of lithe and graceful fairy ludaoli, what kind of most let you move?Christian Louboutin Men Shoes that one brush red is always cannot resist the temptation, Christian Louboutin men outlet continue to use the days of high 8cm above slender heel proclaim the sexy and luxuriant. The bowknot on black pointed high-heeled shoes with sharp rivet concomitant, wild python met enchanting color printing grain, It is that pairs of high-heeled shoes lets Carrie more feminine flavour. Like Christian Louboutin for men her word. |
|
|
| Back to top |
|
|
|
All times are GMT
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|
|