Erlang vs dotnet Core Benchmark in Process/Thread exposure
Hi all,
I wanted to share something significant that I've just discovered!
That is about benchmarking of two popular languages, to be fair .net core is quite a bit more popular.
I know, sometimes it's a matter of running systems rather than performance and might always not be easy to change something that works, even impossible due to need of huge investments.
Here is a simple benchmark of Erlang and .net core environments. Simply, we'll try to expose multiple processes/threads in these languages and compare the timings.
Below is the system where benchmark has been made.
I used Visual Studio Code in Linux to run below codes.
//Creates {max} number of parallel threads.
using System
using System.Linq;
using System.Threading.Tasks;
DateTime anchor = DateTime.Now;
int max = 20000;
Parallel.ForEach(Enumerable.Range(0, max), i => {
Task.Run(() => { }).GetAwaiter().GetResult();
});
System.Console.WriteLine($"Thread count [{max}]. Tasks run time [{((DateTime.Now - anchor).Ticks / (TimeSpan.TicksPerMillisecond / 1000)).ToString("#,#.00")}] microseconds.");
Below erlang code is built using vim
-module(processes).
-export([max/1]).
-purpose("Spawns N number of erlang processes and measures the performance.").
max(N) ->
Max = erlang:system_info(process_limit),
io:format("Maximum allowed processes:~p~n", [Max]),
statistics(runtime),
statistics(wall_clock),
L = for(1, N, fun() -> spawn(fun() -> wait() end) end),
{_, Time1} = statistics(runtime),
{_, Time2} = statistics(wall_clock),
lists:foreach(fun(Pid) -> Pid ! die end, L),
U1 = Time1 * 1000 / N,
U2 = Time2 * 1000 /N,
io:format("Process spawn time = ~p (~p) microseconds~n",
[U1, U2]).
wait() ->
receive
die -> void
end.
for(N, N, F) -> [F()];
for(I, N, F) -> [F() | for(I+1, N, F)].
Recommended by LinkedIn
Now comes the exciting part of it!
When we run the above code in Erlang the results were like below
When we run the c# code in dotnet the results were like below
Conclusion
If you're in a verge of choosing a platform for mission critical and high performing processes then it might be a good idea to consider Erlang.
As you can see from the benchmark above, Erlang is 37,532/4.9~=7,659.60 times faster than dotnet environment in process creation and completion.
But, the fact is, you probably have to be solving problems in financial institutions or telecom sector or have to handle huge amount of data in a short time of period, to have that critical processes. However, it's good to know that you can always use that performant framework like Erlang.
I hope you had patience to reach till here and enjoyed.
Thanks for reading... :)