Since

SortedSmallers = qsort(Smallers),

SortedGreaters = qsort(Greaters),

SortedSmallers ++ [Pivot] ++ SortedGreaters.

is nothing different from

qsort(Smallers) ++ [Pivot] ++ qsort(Greates)

%% Quick Sort

%% Think thru, you’ll see it very easy to understand :p

qsort([]) -> [];

qsort([Single]) -> [Single];

qsort([Pivot|Rest]) ->

{Smallers, Greaters} = qsort(Pivot, Rest),

SortedSmallers = qsort(Smallers),

SortedGreaters = qsort(Greaters),

SortedSmallers ++ [Pivot] ++ SortedGreaters.

qsort(Pivot, List) -> qsort(Pivot, [], [], List).

qsort(_Pivot, Smallers, Greaters, []) -> {Smallers, Greaters};

qsort(Pivot, Smallers, Greaters, [First|Rest]) when First

qsort(Pivot, [First|Smallers], Greaters, Rest);

qsort(Pivot, Smallers, Greaters, [First|Rest]) when First >= Pivot ->

qsort(Pivot, Smallers, [First|Greaters], Rest).

I was also confused about “++” vs. “lists:concat”, then I write a simple test, it seems “lists:concat” was obviously faster. I think Denny is right, the BIFs may not be implemented in Erlang indeed.

The “string:concat/2″ seems not very useful compared to “lists:concat/1″, since it only takes two arguments.

Hope the author will make a comparison to these functions ðŸ˜‰ ]]>

If you have a book Programming Erlang from Joe Amstrong, in chapter 8, section 8.4 mentions about the performance of spawning a process. You can refer to it for more details.

In a nut shell, you can use erlang:system_info(process_limit) to find out the max number of process you can create. If I have time, I will create a post about this.

Thanks,

Trung

]]>thanks

]]>