The Computer Language
Benchmarks Game

thread-ring Erlang HiPE program

source code

% The Computer Language Benchmarks Game
% http://benchmarksgame.alioth.debian.org/
%%% Contributed by Jiri Isa
%%% optimized run time options by shun shino

-module(threadring).
-export([main/1, roundtrip/2]).

-define(RING, 503).

start(Token) ->
   H = lists:foldl(
      fun(Id, Pid) -> spawn(threadring, roundtrip, [Id, Pid]) end, 
      self(), 
      lists:seq(?RING, 2, -1)),
   H ! Token,
   roundtrip(1, H).

roundtrip(Id, Pid) ->
   receive
      1 ->
         io:fwrite("~b~n", [Id]),
         erlang:halt();
      Token ->
         Pid ! Token - 1,
         roundtrip(Id, Pid)
   end.

main([Arg]) ->
   Token = list_to_integer(Arg),
   start(Token).
    

notes, command-line, and program output

NOTES:
64-bit Ubuntu quad core
Erlang/OTP 20 [erts-9.1] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:10] [hipe] [kernel-poll:false]


Wed, 08 Nov 2017 01:32:03 GMT

MAKE:
mv threadring.hipe threadring.erl
/opt/src/otp_src_20.1/bin/erlc +native +"{hipe, [o3]}" threadring.erl
rm threadring.erl

0.44s to complete and log all make actions

COMMAND LINE:
/opt/src/otp_src_20.1/bin/erl -smp enable -noshell -run  threadring main 50000000

PROGRAM OUTPUT:
292