Skip to content

Commit

Permalink
fix benchmark scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
lindahua committed Jan 26, 2017
1 parent 50707f2 commit 4f6a2ac
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
32 changes: 16 additions & 16 deletions test/benchmark.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ end


function perf_view(a::Array, i1; rtimes::Int=100000)
et_s, _ = time_view1d(sub(a, i1), rtimes)
et_v, _ = time_view1d(view(a, i1), rtimes)
et_s, _ = time_view1d(Base.view(a, i1), rtimes)
et_v, _ = time_view1d(aview(a, i1), rtimes)
et_u, _ = time_view1d(unsafe_aview(a, i1), rtimes)

v = view(a, i1)
v = aview(a, i1)
mps_s = mps(v, rtimes, et_s)
mps_v = mps(v, rtimes, et_v)
mps_u = mps(v, rtimes, et_u)
Expand All @@ -83,11 +83,11 @@ function perf_view(a::Array, i1; rtimes::Int=100000)
end

function perf_view(a::Array, i1, i2; rtimes::Int=100000)
et_s, _ = time_view2d(sub(a, i1, i2), rtimes)
et_v, _ = time_view2d(view(a, i1, i2), rtimes)
et_s, _ = time_view2d(Base.view(a, i1, i2), rtimes)
et_v, _ = time_view2d(aview(a, i1, i2), rtimes)
et_u, _ = time_view2d(unsafe_aview(a, i1, i2), rtimes)

v = view(a, i1, i2)
v = aview(a, i1, i2)
mps_s = mps(v, rtimes, et_s)
mps_v = mps(v, rtimes, et_v)
mps_u = mps(v, rtimes, et_u)
Expand All @@ -97,11 +97,11 @@ function perf_view(a::Array, i1, i2; rtimes::Int=100000)
end

function perf_view(a::Array, i1, i2, i3; rtimes::Int=100000)
et_s, _ = time_view3d(sub(a, i1, i2, i3), rtimes)
et_v, _ = time_view3d(view(a, i1, i2, i3), rtimes)
et_s, _ = time_view3d(Base.view(a, i1, i2, i3), rtimes)
et_v, _ = time_view3d(aview(a, i1, i2, i3), rtimes)
et_u, _ = time_view3d(unsafe_aview(a, i1, i2, i3), rtimes)

v = view(a, i1, i2, i3)
v = aview(a, i1, i2, i3)
mps_s = mps(v, rtimes, et_s)
mps_v = mps(v, rtimes, et_v)
mps_u = mps(v, rtimes, et_u)
Expand All @@ -112,24 +112,24 @@ end

# benchmarks

println("Indexing sub view unsafe_aview")
println("Indexing Base.view aview unsafe_aview")
println("--------------------------------------------------------------------------------------------------")

const a1 = rand(1024)

gc_disable()
gc_enable(false)

println("1D views")
perf_view(a1, :)
perf_view(a1, 1:1024)
perf_view(a1, 1:2:1024)
println()

gc_enable()
gc_enable(true)

const a2 = rand(32, 32)

gc_disable()
gc_enable(false)

println("2D views")
perf_view(a2, :, :)
Expand All @@ -145,11 +145,11 @@ perf_view(a2, 1:2:30, 1:32)
perf_view(a2, 1:2:30, 1:2:32)
println()

gc_enable()
gc_enable(true)

const a3 = rand(16, 8, 8)

gc_disable()
gc_enable(false)

println("3D views")
perf_view(a3, :, :, :)
Expand Down Expand Up @@ -189,4 +189,4 @@ perf_view(a3, 1:2:16, 1:2:8, 1:8)
perf_view(a3, 1:2:16, 1:2:8, 1:2:8)
println()

gc_enable()
gc_enable(true)
12 changes: 6 additions & 6 deletions test/benchmark_construct.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ using ArrayViews
function traverse_row_subs(a::Array, r::Int)
m = size(a, 1)
for _ = 1:r, i = 1:m
sub(a, i, :)
Base.view(a, i, :)
end
end

function traverse_row_views(a::Array, r::Int)
m = size(a, 1)
for _ = 1:r, i = 1:m
view(a, i, :)
aview(a, i, :)
end
end

Expand All @@ -26,14 +26,14 @@ end
function traverse_column_subs(a::Array, r::Int)
n = size(a, 2)
for _ = 1:r, i = 1:n
sub(a, :, i)
Base.view(a, :, i)
end
end

function traverse_column_views(a::Array, r::Int)
n = size(a, 2)
for _ = 1:r, i = 1:n
view(a, :, i)
aview(a, :, i)
end
end

Expand Down Expand Up @@ -64,7 +64,7 @@ m1 = 1.0 / et1
m2 = 1.0 / et2
m3 = 1.0 / et3

@printf("Traverse Rows: subs => %7.4f M/sec views => %7.4f M/sec (%6.3fx) unsafe_views => %7.4f M/sec (%6.3fx)\n",
@printf("Traverse Rows: Base.view => %7.4f M/sec aview => %7.4f M/sec (%6.3fx) unsafe_aview => %7.4f M/sec (%6.3fx)\n",
m1, m2, m2 / m1, m3, m3 / m1)

# traverse cols
Expand All @@ -81,5 +81,5 @@ m1 = 1.0 / et1
m2 = 1.0 / et2
m3 = 1.0 / et3

@printf("Traverse Cols: subs => %7.4f M/sec views => %7.4f M/sec (%6.3fx) unsafe_views => %7.4f M/sec (%6.3fx)\n",
@printf("Traverse Cols: Base.view => %7.4f M/sec aview => %7.4f M/sec (%6.3fx) unsafe_aview => %7.4f M/sec (%6.3fx)\n",
m1, m2, m2 / m1, m3, m3 / m1)

0 comments on commit 4f6a2ac

Please sign in to comment.