Last active
December 17, 2017 04:11
-
-
Save sourabh2k15/d0135642b089ec6a2ea978d6cd3b30fa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Async do | |
@n_clients 100000 | |
def createFollowersSync(n_clients) do | |
Enum.reduce(1..n_clients, [], fn rank, acc -> | |
acc ++ [Util.pickRandom(@n_clients, rank)] | |
end) | |
end | |
def createFollowersAsync(n_clients) do | |
chunks = Enum.chunk_every(1..n_clients, 1000) | |
chunked_tasks = Enum.map(chunks, fn chunk -> | |
Task.async(fn -> | |
Enum.reduce(chunk, [], fn x, acc -> | |
acc ++ [Util.pickRandom(@n_clients, x)] | |
end) | |
end) | |
end) | |
Enum.reduce(chunked_tasks, [], fn chunk_task, acc -> | |
acc ++ Task.await(chunk_task) | |
end) | |
end | |
def start do | |
start_time = :os.system_time(:milli_seconds) | |
followers = createFollowersAsync(@n_clients) | |
end_time_1 = :os.system_time(:milli_seconds) | |
IO.inspect followers | |
IO.puts length(followers) | |
IO.puts "took #{(end_time_1 - start_time)}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
util module :