Guest User

Untitled

a guest
Dec 17th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. defmodule HashData do
  2. def open_file do
  3. File.read! "rand.txt"
  4. end
  5.  
  6. def hash_contents(n) do
  7. open_file()
  8. |> hash_contents(n)
  9. end
  10.  
  11. def hash_contents(hash, n) when n < 1 do
  12. hash
  13. |> Base.encode16
  14. |> String.downcase
  15. end
  16.  
  17. def hash_contents(hash, n) do
  18. :crypto.hash(:sha256, hash)
  19. |> hash_contents(n - 1)
  20. end
  21. end
  22.  
  23. defmodule Benchmark do
  24. def measure(function) do
  25. function
  26. |> :timer.tc
  27. |> elem(0)
  28. |> Kernel./(1_000_000)
  29. end
  30. end
Add Comment
Please, Sign In to add comment