Skip to content

Commit

Permalink
update README
Browse files Browse the repository at this point in the history
  • Loading branch information
vchuravy committed Nov 15, 2017
1 parent 0365e17 commit cb9ca74
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -52,27 +52,44 @@ function f(x, a)
s
end

using Benchmarks
using BenchmarkTools
@benchmark f(regular, 0.5+0.5im)
@benchmark f(soa, 0.5+0.5im)
```

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.

0 comments on commit cb9ca74

Please sign in to comment.