Skip to content

Commit 6bb0093

Browse files
authored
Improve benchmarking and examples (#37)
* Use @Btime and fixed `out` assignment * Improved replaceBase macro examples - Remove extra dot in the macro arguments for ^ and / operators. - Added benchmark example for ^
1 parent f657cb9 commit 6bb0093

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

README.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,30 @@ To avoid naming conflicts with Base, methods are not exported and so need to
3737
be accessed via the namespace:
3838
```julia
3939
using AppleAccelerate
40-
X = randn(1_000_000)
41-
@time Y = exp(X) # standard libm function
42-
@time Y = AppleAccelerate.exp(X) # Accelerate array-oriented function
40+
using BenchmarkTools
41+
X = randn(1_000_000);
42+
@btime exp.($X); # standard libm function
43+
@btime AppleAccelerate.exp($X); # Accelerate array-oriented function
4344
```
4445

4546
The `@replaceBase` macro replaces the relevant Base methods directly
4647
```julia
48+
@btime sin.($X); # standard libm function
4749
AppleAccelerate.@replaceBase sin cos tan
48-
AppleAccelerate.@replaceBase(.^, ./) # use parenthesised form for infix ops
49-
@time sin(X) # will use AppleAccelerate methods for vectorised operations
50+
@btime sin($X); # will use AppleAccelerate methods for vectorised operations
51+
52+
X = randn(1_000_000);
53+
Y = fill(3.0, 1_000_000);
54+
@btime $X .^ $Y;
55+
AppleAccelerate.@replaceBase(^, /) # use parenthesised form for infix ops
56+
@btime $X ^ $Y;
5057
```
5158

5259
Output arrays can be specified as first arguments of the functions suffixed
5360
with `!`:
5461
```julia
55-
out = Array(Float64,1_000_000)
56-
@time AppleAccelerate.exp!(out, X)
62+
out = zeros(Float64, 1_000_000)
63+
@btime AppleAccelerate.exp!($out, $X)
5764
```
5865

5966
**Warning**: no dimension checks are performed on the `!` functions, so ensure

0 commit comments

Comments
 (0)