@ -1,4 +1,6 @@
defmodule PerfTest do
Code . require_file " test_helper.exs " , __DIR__
defmodule PerformanceTest do
use ExUnit.Case
defrecord TestCtxt ,
@ -7,13 +9,6 @@ defmodule PerfTest do
time : 0
test " 10,000 concats " do
threshold = 30_000 #30 milliseconds
time = build_rope |> build_ctxt |> run ( 10_000 , :concat )
IO . puts " \n ROPE: 10,000 concats took #{ time } microseconds "
assert time < threshold , " 10,000 concats completed in #{ time } microseconds, longer then threshold of #{ threshold } microseconds "
end
test " rebalancing 100,000 words " do
threshold = 100_000 #100 milliseconds
time = build_long_rope |> build_ctxt |> run ( 1 , :rebalance )
@ -21,29 +16,57 @@ defmodule PerfTest do
assert time < threshold , " rebalancing worst case 100,000 leaf rope completed in #{ time } microseconds, longer then threshold of #{ threshold } microseconds "
end
test " 1,000 slices on a balanced rope " do
threshold = 175_000 #100 milliseconds
time = build_rope |> build_ctxt |> run ( 1_000 , :slice )
IO . puts " \n ROPE: 1,000 slice took #{ time } microseconds "
assert time < threshold , " 1,000 slices on a balanced rope completed in #{ time } microseconds, longer then threshold of #{ threshold } microseconds "
test " small rope performance " do
threshold = 3_000 #3 milliseconds
time = build_rope |> build_ctxt |> run ( 1_000 , :concat )
IO . puts " \n SMALL ROPE: 1,000 concats took #{ time } microseconds "
assert time < threshold , " 1,000 concats completed in #{ time } microseconds, longer then threshold of #{ threshold } microseconds "
threshold = 17_000 #100 milliseconds
time = build_rope |> build_ctxt |> run ( 10 , :slice )
IO . puts " \n SMALL ROPE: 10 slice took #{ time } microseconds "
assert time < threshold , " 10 slices on a balanced rope completed in #{ time } microseconds, longer then threshold of #{ threshold } microseconds "
threshold = 1_000
time = build_rope |> build_ctxt |> run ( 10 , :find )
IO . puts " \n SMALL ROPE: 10 find took #{ time } microseconds "
assert time < threshold , " 10 finds on a balanced rope completed in #{ time } microseconds, longer then threshold of #{ threshold } microseconds "
end
test " 100 finds on a balanced rope " do
threshold = 1_000 #1/2 second
time = build_rope |> build_ctxt |> run ( 100 , :find )
IO . puts " \n ROPE: 100 find took #{ time } microseconds "
assert time < threshold , " 100 finds on a balanced rope completed in #{ time } microseconds, longer then threshold of #{ threshold } microseconds "
test " huge rope performance " do
threshold = 3_000 #3 milliseconds
time = build_huge_rope |> build_ctxt |> run ( 1_000 , :concat )
IO . puts " \n HUGE ROPE: 1,000 concats took #{ time } microseconds "
assert time < threshold , " 1,000 concats completed in #{ time } microseconds, longer then threshold of #{ threshold } microseconds "
threshold = 40_000 #40 milliseconds
time = build_huge_rope |> build_ctxt |> run ( 10 , :slice )
IO . puts " \n HUGE ROPE: 10 slice took #{ time } microseconds "
assert time < threshold , " 10 slices on a balanced rope completed in #{ time } microseconds, longer then threshold of #{ threshold } microseconds "
IO . puts " \n HUGE ROPE: 10 find took nevermind microseconds "
end
test " string performance " do
time = build_text |> build_ctxt |> run ( 10_000 , :concat )
IO . puts " \n STRING: 10,000 concats took #{ time } microseconds "
test " small s tring performance " do
time = build_text |> build_ctxt |> run ( 1_000 , :concat )
IO . puts " \n SMALL S TRING: 1,000 concats took #{ time } microseconds "
time = build_text |> build_ctxt |> run ( 1_000 , :slice )
IO . puts " \n STRING: 1,00 0 slices took #{ time } microseconds "
time = build_text |> build_ctxt |> run ( 10 , :slice )
IO . puts " \n SMALL S TRING: 10 slices took #{ time } microseconds "
time = build_text |> build_ctxt |> run ( 100 , :find )
IO . puts " \n STRING: 100 contains? took #{ time } microseconds "
time = build_text |> build_ctxt |> run ( 10 , :find )
IO . puts " \n SMALL STRING: 10 contains? took #{ time } microseconds "
end
test " huge string performance " do
time = build_huge_text |> build_ctxt |> run ( 1000 , :concat )
IO . puts " \n HUGE STRING: 1,000 concats took #{ time } microseconds "
time = build_huge_text |> build_ctxt |> run ( 10 , :slice )
IO . puts " \n HUGE STRING: 10 slices took #{ time } microseconds "
time = build_huge_text |> build_ctxt |> run ( 10 , :find )
IO . puts " \n HUGE STRING: 10 contains? took #{ time } microseconds "
end
@ -57,6 +80,12 @@ defmodule PerfTest do
|> Rope . rebalance
end
def build_huge_rope do
File . stream! ( " test/fixtures/dracula.txt " )
|> Enum . reduce ( " " , fn ( line , rope ) -> Rope . concat ( rope , line ) end )
|> Rope . rebalance
end
def build_long_rope ( ) do
extra = build_extra
Enum . reduce ( 1 . . 100_000 , " " , fn ( _count , left ) ->
@ -72,6 +101,10 @@ defmodule PerfTest do
File . read! ( " test/fixtures/hello_ground.txt " )
end
def build_huge_text do
File . read! ( " test/fixtures/dracula.txt " )
end
def get_timestamp do
{ mega , sec , micro } = :erlang . now ( )
( mega * 1000000 + sec ) * 1000000 + micro