Created
December 14, 2017 19:51
-
-
Save cliffom/f4c08177fe7fbca3327217f2b6b41d9c to your computer and use it in GitHub Desktop.
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
defmodule HashData do | |
def open_file do | |
File.read! "rand.txt" | |
end | |
def hash_contents(n) do | |
open_file() | |
|> hash_contents(n) | |
end | |
def hash_contents(hash, n) when n < 1 do | |
hash | |
|> Base.encode16 | |
|> String.downcase | |
end | |
def hash_contents(hash, n) do | |
:crypto.hash(:sha256, hash) | |
|> hash_contents(n - 1) | |
end | |
end | |
defmodule Benchmark do | |
def measure(function) do | |
function | |
|> :timer.tc | |
|> elem(0) | |
|> Kernel./(1_000_000) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bench with:
Benchmark.measure(fn -> HashData.hash_contents(100_000_000) end)