Skip to content

Commit

Permalink
fix(elixir): use processes directly
Browse files Browse the repository at this point in the history
  • Loading branch information
spurreiter committed Dec 2, 2024
1 parent ce7a529 commit 64b557f
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 55 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Lower values are better.
| Implementation | 10k | 100k | 1M |
| -------------- | --: | ---: | ----: |
| dotnet | 22M | 38M | 190M |
| elixir | 95M | 446M | 3854M |
| elixir | 88M | 343M | 3080M |
| go | 29M | 261M | 2571M |
| java | 93M | 170M | 1001M |
| nodejs | 26M | 107M | 666M |
Expand Down
28 changes: 28 additions & 0 deletions elixir/main.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Use processes directly @josevalim

defmodule Main do
def start() do
num_tasks =
case System.argv() |> List.first() |> Integer.parse() do
{num, _} -> num
_ -> 10000
end

tasks =
for _ <- 1..num_tasks do
spawn_monitor(fn ->
:timer.sleep(10000)
end)
end

for {_pid, ref} <- tasks do
receive do
{:DOWN, ^ref, _, _, _} -> :ok
end
end

IO.puts("All tasks completed")
end
end

Main.start()
3 changes: 3 additions & 0 deletions elixir/tasks.ex → elixir/tasks.exs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Tasks are a higher-level abstraction and they will include additional features
# for tracking responses.

defmodule Tasks do
use Task

Expand Down
2 changes: 1 addition & 1 deletion results.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Lower values are better.
| Implementation | 10k | 100k | 1M |
| -------------- | --: | ---: | ----: |
| dotnet | 22M | 38M | 190M |
| elixir | 95M | 446M | 3854M |
| elixir | 88M | 343M | 3080M |
| go | 29M | 261M | 2571M |
| java | 93M | 170M | 1001M |
| nodejs | 26M | 107M | 666M |
Expand Down
110 changes: 57 additions & 53 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,98 +8,98 @@ set +x
parallel=${2:-10000}

status () {
local opts
if [ $(uname) = "Darwin" ]; then
opts="-l 15"
else
opts="-b -n15"
fi
top $opts -pid $1 -stats pid,cpu,mem | egrep "$1"
local opts
if [ $(uname) = "Darwin" ]; then
opts="-l 15"
else
opts="-b -n15"
fi
top $opts -pid $1 -stats pid,cpu,mem | egrep "$1"
}

_dotnet () {
cd dotnet
dotnet publish -c Release --self-contained true
exec ./bin/Release/net9.0/osx-arm64/publish/dotnet $parallel &
status $!
cd dotnet
dotnet publish -c Release --self-contained true
exec ./bin/Release/net9.0/osx-arm64/publish/dotnet $parallel &
status $!
}

_elixir () {
cd elixir
exec elixir tasks.ex $parallel &
status $!
cd elixir
exec elixir main.exs $parallel &
status $!
}

_go () {
cd go
go build
exec ./coroutines $parallel &
status $!
cd go
go build
exec ./coroutines $parallel &
status $!
}

_java () {
cd java
exec java VirtualThreads.java $parallel &
status $!
cd java
exec java VirtualThreads.java $parallel &
status $!
}

_nodejs () {
cd nodejs
exec node main.js $parallel &
status $!
cd nodejs
exec node main.js $parallel &
status $!
}

_bun () {
cd nodejs
exec bun run main.js $parallel &
status $!
cd nodejs
exec bun run main.js $parallel &
status $!
}

_deno () {
cd nodejs
exec deno run main.js $parallel &
status $!
cd nodejs
exec deno run main.js $parallel &
status $!
}

_python () {
cd python
exec python3 main.py $parallel &
status $!
cd python
exec python3 main.py $parallel &
status $!
}

_rust_async_std () {
cd rust_async_std
cargo build -r
exec ./target/release/rust_async_std $parallel &
local pid=$!
status $pid
cd rust_async_std
cargo build -r
exec ./target/release/rust_async_std $parallel &
local pid=$!
status $pid
}

_rust_futures () {
cd rust_futures
cargo build -r
exec ./target/release/rust_futures $parallel &
local pid=$!
status $pid
cd rust_futures
cargo build -r
exec ./target/release/rust_futures $parallel &
local pid=$!
status $pid
}

_rust_tokio () {
cd rust_tokio
cargo build -r
exec ./target/release/rust_tokio $parallel &
local pid=$!
status $pid
cd rust_tokio
cargo build -r
exec ./target/release/rust_tokio $parallel &
local pid=$!
status $pid
}

_all () {
for cmd in dotnet elixir go java nodejs bun deno python rust_async_std rust_futures rust_tokio; do
echo === $cmd ===
./run.sh $cmd $parallel
done
for cmd in dotnet elixir go java nodejs bun deno python rust_async_std rust_futures rust_tokio; do
echo === $cmd ===
./run.sh $cmd $parallel
done
}

_versions () {
cat << EOS
cat << EOS
- dotnet: $(dotnet --version)
- elixir: $(elixir --version | tail -1)
- go: $(go version)
Expand All @@ -112,6 +112,10 @@ _versions () {
EOS
}

_docs () {
markedpp -s -i README.md
}

# ... ignition ...

function help {
Expand Down

0 comments on commit 64b557f

Please sign in to comment.