From cb9ca749d4c44c8438ab03b3965bafa391b01a07 Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Wed, 15 Nov 2017 11:57:52 -0500 Subject: [PATCH] update README --- README.md | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 1f2d721..1c34714 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ A = StructOfArrays(Complex128, 10, 10) or by converting an AbstractArray: ```julia -A = convert(StructOfArrays, complex(randn(10), randn(10))) +A = convert(StructOfArrays, complex.(randn(10), randn(10))) ``` Beyond that, there's not much to say. Assignment and indexing works as with @@ -41,7 +41,7 @@ works best with `isbits` immutables such as `Complex{T}`. ```julia using StructsOfArrays -regular = complex(randn(1000000), randn(1000000)) +regular = complex.(randn(1000000), randn(1000000)) soa = convert(StructOfArrays, regular) function f(x, a) @@ -52,7 +52,7 @@ function f(x, a) s end -using Benchmarks +using BenchmarkTools @benchmark f(regular, 0.5+0.5im) @benchmark f(soa, 0.5+0.5im) ``` @@ -60,19 +60,36 @@ using Benchmarks The time for `f(regular, 0.5+0.5im)` is: ``` -Average elapsed time: 1.244 ms - 95% CI for average: [1.183 ms, 1.305 ms] -Minimum elapsed time: 1.177 ms +BenchmarkTools.Trial: + memory estimate: 64 bytes + allocs estimate: 2 + -------------- + minimum time: 811.481 μs (0.00% GC) + median time: 827.617 μs (0.00% GC) + mean time: 845.552 μs (0.00% GC) + maximum time: 2.336 ms (0.00% GC) + -------------- + samples: 5880 + evals/sample: 1 ``` and for `f(soa, 0.5+0.5im)`: ``` -Average elapsed time: 832.198 μs - 95% CI for average: [726.349 μs, 938.048 μs] -Minimum elapsed time: 713.730 μs +BenchmarkTools.Trial: + memory estimate: 64 bytes + allocs estimate: 2 + -------------- + minimum time: 491.044 μs (0.00% GC) + median time: 517.429 μs (0.00% GC) + mean time: 598.599 μs (0.00% GC) + maximum time: 4.634 ms (0.00% GC) + -------------- + samples: 8262 + evals/sample: 1 ``` In this case, StructsOfArrays are about 1.5x faster than ordinary arrays. Inspection of generated code demonstrates that `f(soa, a)` uses SIMD -instructions, while `f(regular, a)` does not. +instructions with a optimal data layout, while `f(regular, a)` +does use SIMD instructions (on Julia 0.7), but does not use a optimal data layout.