chungwong

chungwong

Elixir NIF performance compared to native C++

I have a library which is written in C++, and I wrote a NIF “bridge” for it.

When I bench marked the library in C++, it had ~400-600 ips.

Then I bench marked it in Elixir, the result surprised me and it reached minimum 4k ips.

I couldn’t believe my eyes so I spinning a drogon http server to battle with Phoenix.

And the results from the two stay pretty much the same ~400 rps vs ~3k-6k rps.

How come a native C++ call is MUCH slower than the one from Elixir NIF?

Most Liked

rjk

rjk

Are you able to share the code? It would be easier this way to say something sensible about it.
But from my own experience it’s quite difficult to measure between 2 platforms in a correct way.
(I’m using rustler myself and performance seems to be faster on the 100% rust side, I have never seen the elixir/NIF part being faster because of the (sometimes little) overhead crossing the NIF bridge)

yurko

yurko

Could be that your benchmarks are parallelized for BEAM but not when testing native C++?

hauleth

hauleth

As @rjk and @yurko said, it can depend on many things. If you could provide MCVE so we could check this out, then maybe we could give you more correct answer.

Last Post!

hauleth

hauleth

20’000 iterations in 20 seconds mean less throughput than 2’000 iterations in 1 second. And from what I see Google Bench gives you amount of iterations, not IPS.

Where Next?

Popular in Questions Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

Other popular topics Top

jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 40042 209
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 44139 214
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

We're in Beta

About us Mission Statement