Skip to content

Instantly share code, notes, and snippets.

@ZaneH
Last active August 27, 2023 17:18
Show Gist options
  • Save ZaneH/f3ddce1ec0d778d6f8b7c4e439a2828f to your computer and use it in GitHub Desktop.
Save ZaneH/f3ddce1ec0d778d6f8b7c4e439a2828f to your computer and use it in GitHub Desktop.
Benchmark Jimp image generation from Elixir
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
})
@ZaneH
Copy link
Author

ZaneH commented Aug 27, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment