Last active
August 29, 2015 14:10
-
-
Save stoft/046a555713c80a41b8ca to your computer and use it in GitHub Desktop.
Exercism exercise "point mutations" performance test.
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
if System.get_env("EXERCISM_TEST_EXAMPLES") do | |
Code.load_file("example.exs") | |
else | |
Code.load_file("point_mutations.exs") | |
end | |
ExUnit.start | |
defmodule DNATest do | |
use ExUnit.Case, async: true | |
@nucleotides %{1 => ?A, 2 => ?C, 3 => ?G, 4 => ?T} | |
test "hamming distance large length" do | |
start = :erlang.now | |
{list1, list2} = gen_hamming_dna([], [], 1_000_000) | |
finish = :erlang.now | |
IO.puts :timer.now_diff(finish, start) | |
start = :erlang.now | |
IO.puts DNA.hamming_distance(list1, list2) | |
finish = :erlang.now | |
IO.puts :timer.now_diff(finish, start) | |
end | |
def gen_hamming_dna(list1, list2, 0), do: {list1, list2} | |
def gen_hamming_dna(list1, list2, length) do | |
if rem(length, 10) == 0 do | |
nuc1 = get_nucleotide() | |
nuc2 = get_nucleotide() | |
gen_hamming_dna([nuc1|list1], [nuc2|list2], length - 1) | |
else | |
nuc = get_nucleotide() | |
gen_hamming_dna([nuc|list1], [nuc|list2], length - 1) | |
end | |
end | |
def get_nucleotide() do | |
@nucleotides[:random.uniform(4)] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment