All Projects → tatsuya6502 → Elixir_rust_interop_demo

tatsuya6502 / Elixir_rust_interop_demo

Licence: mit
Demonstrate calling Rust functions from Elixir using Erlang NIF interface

Programming Languages

rust
11053 projects
elixir
2628 projects
erlang
1774 projects

Labels

Projects that are alternatives of or similar to Elixir rust interop demo

Testing Nestjs
A repository to show off to the community methods of testing NestJS including Unit Tests, Integration Tests, E2E Tests, pipes, filters, interceptors, GraphQL, Mongo, TypeORM, and more!
Stars: ✭ 685 (+4466.67%)
Mutual labels:  examples
Sense Extension Recipes
A collection of recipes to speed up development of Qlik Sense Visualization Extensions.
Stars: ✭ 17 (+13.33%)
Mutual labels:  examples
Introduction
Code examples and additional documentation for using Calimero
Stars: ✭ 10 (-33.33%)
Mutual labels:  examples
Sciblog support
Support content for my blog
Stars: ✭ 694 (+4526.67%)
Mutual labels:  examples
Examples
Example projects that demonstrate how to use Expo APIs and integrate Expo with other popular tools
Stars: ✭ 747 (+4880%)
Mutual labels:  examples
Rxswiftexamples
Examples and resources for RxSwift.
Stars: ✭ 930 (+6100%)
Mutual labels:  examples
Cl Cookbook
The Common Lisp Cookbook
Stars: ✭ 638 (+4153.33%)
Mutual labels:  examples
Elements Examples
Stripe Elements examples.
Stars: ✭ 874 (+5726.67%)
Mutual labels:  examples
Ethereum Development With Go Book
📖 A little book on Ethereum Development with Go (golang)
Stars: ✭ 754 (+4926.67%)
Mutual labels:  examples
Spring Boot Rest Api Example
Implement REST APIs using Spring Boot and Spring Session.
Stars: ✭ 10 (-33.33%)
Mutual labels:  examples
Recipes
📁 Examples for 🚀 Fiber
Stars: ✭ 691 (+4506.67%)
Mutual labels:  examples
Grpc By Example Java
A collection of useful/essential gRPC Java Examples
Stars: ✭ 709 (+4626.67%)
Mutual labels:  examples
Haxejs
Documentation about using JavaScript with Haxe
Stars: ✭ 25 (+66.67%)
Mutual labels:  examples
Py2rs
A quick reference guide for the Pythonista in the process of becoming a Rustacean
Stars: ✭ 690 (+4500%)
Mutual labels:  examples
Jaxws Samples
Small example projects using JAX-WS technologies.
Stars: ✭ 11 (-26.67%)
Mutual labels:  examples
Antons opengl tutorials book
Anton's OpenGL 4 Tutorials book - Demo Code
Stars: ✭ 668 (+4353.33%)
Mutual labels:  examples
Kotlin Android Examples
💪 [Examples] Isolated applications purely on Kotlin, for all android devs out there
Stars: ✭ 902 (+5913.33%)
Mutual labels:  examples
Cht.exe
cht.sh libcurl client for windows XP+ with changed colorization
Stars: ✭ 15 (+0%)
Mutual labels:  examples
Handyhaskell
💙 Code from the HandyHaskell twitter page
Stars: ✭ 13 (-13.33%)
Mutual labels:  examples
Php Ffi Examples
Runnable examples to learn how PHP FFI works
Stars: ✭ 26 (+73.33%)
Mutual labels:  examples

Elixir Rust Interop Demo

This project demonstrates calling Rust functions from Elixir using Erlang NIF interface. It depends on ruster_unsafe crate, a low level bindings to Erlang NIF API for Rust.

Recently Tested With

  • Elixir 1.2.0 on Erlang/OTP 18.2.1 with dirty schedulers and HiPE enabled
  • Rust 1.5

Requirements

  • Elixir 1.2.0 or newer is recommended.
  • Erlang/OTP 17.0 or newer. 18.0 or newer is recommended because Elixir 1.2.0 requires 18.0.
  • Rust 1.5 or newer is recommended.

Erlang/OTP Build Options

These Rust functions take advantage of experimental "dirty schedulers" in Erlang/OTP 17.0 or newer, so please enable this feature.

  • Erlang/OTP must be built with --enable-dirty-schedulers
  • Optionally, Erlang/OTP can be build with --enable-hipe, or with both --enable-hipe --enable-native-libs

Running the Program

First of all, clone and build the project. This will build both Rust and Elixir stuffs.

git clone https://github.com/tatsuya6502/elixir_rust_interop_demo.git
cd elixir_rust_interop_demo
iex -S mix

Calling a Regular Elixir Function

Try to call an Elixir function to calculate an approximate number of Pi in parallel (10 concurrent processes).

iex> :timer.tc(fn() -> Pi.calc_pi_parallel(1_000_000_000, 10) end)
{29319387, {:ok, 3.141592655589816}}

Enable HiPE

You may also try HiPE. From another terminal window, compile Pi module with hipe option.

cd elixir_rust_interop_demo
ERL_COMPILER_OPTIONS="[native, {hipe, [o3]}]" elixirc -o _build/dev/lib/elixir_rust_interop_demo/ebin/ lib/pi.ex

Then run it.

iex> l Pi
iex> :code.is_module_native(Pi)
true
iex> :timer.tc(fn() -> Pi.calc_pi_parallel(1_000_000_000, 10) end)
{15226457, {:ok, 3.141592655589816}}

Calling a Rust Function from Elixir via Erlang NIF interface

Calling a Rust function from an Elixir function to calculate an approximate number of Pi in parallel (10 concurrent threads).

iex> :timer.tc(fn() -> PiNif.calc_pi_parallel(1_000_000_000, 10) end)
{1209160, {:ok, 3.141592655589816}}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].