-
-
Save ZaneH/f3ddce1ec0d778d6f8b7c4e439a2828f to your computer and use it in GitHub Desktop.
Benchmark Jimp image generation from Elixir
This file contains 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
lifecycle_images = [ | |
"apple-tree-none.png", | |
"apple-tree-some.png", | |
"apple-tree-full.png" | |
] | |
list = Enum.to_list(1..100) | |
dummy_states = Enum.map(list, fn i -> | |
# 10 plants | |
Enum.map(1..10, fn p -> | |
%{ | |
x: rem(p + i, 6) + 1, | |
y: rem(p + i, 6) + 1, | |
image: Enum.at(lifecycle_images, :rand.uniform(3) - 1) | |
} | |
end) | |
end) | |
generate_image = fn state -> | |
{:ok, path} = | |
NodeJS.call("app", [ | |
Jason.encode!(%{"discord_user_id" => "123", "state" => state}) | |
]) | |
path | |
end | |
Benchee.run(%{ | |
"generate_image" => fn -> Enum.map(dummy_states, generate_image) end | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Original article: https://zaaane.com/blog/generating-images-for-a-discord-game