-
Notifications
You must be signed in to change notification settings - Fork 38
/
benchmark_doc.jl
151 lines (118 loc) · 4.53 KB
/
benchmark_doc.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# generate benchmarks for documentation
function generate_docbenchmark()
a = tensor_dict[(3, 1, Float64)]
A = tensor_dict[(3, 2, Float64)]
As = symtensor_dict[(3, 2, Float64)]
AA = tensor_dict[(3, 4, Float64)]
AAs = symtensor_dict[(3, 4, Float64)]
# arrays and voigt forms
b = Array(a)
B = Array(A); Bv = reshape(B, (9, ))
Bs = Array(As); Bsv = reshape(Bs, (9, ))
BB = Array(AA); BBv = reshape(BB, (9, 9))
BBs = Array(AAs); BBsv = reshape(BBs, (9, 9))
open(joinpath(dirname(@__FILE__), "../docs/src/benchmarks.md"), "w") do file
function printheader(head)
println(file, "| **$(head)** | | | |")
end
function printrow(op)
pretty = (t) -> BenchmarkTools.prettytime(BenchmarkTools.time(minimum(t)))
speedup = (ta, tt) -> round(10*BenchmarkTools.time(minimum(ta))/BenchmarkTools.time(minimum(tt)))/10
println(file, "| `$(op)` | $(pretty(tt)) | $(pretty(ta)) | ×$(speedup(ta, tt)) |")
end
print(file, """
# Benchmarks
Here are some benchmark timings for tensors in 3 dimensions. For comparison
the timings for the same operations using standard Julia `Array`s are also
presented.
In the table below, `a` denotes a vector, `A`, `As` denotes second order
non-symmetric and symmetric tensors and `AA`, `AAs` denotes fourth order
non-symmetric and symmetric tensors respectively.
| Operation | `Tensor` | `Array` | speed-up |
|:-----------|---------:|--------:|---------:|
""")
printheader("Single contraction")
tt = @benchmark $a ⋅ $a
ta = @benchmark $b ⋅ $b
printrow("a ⋅ a")
tt = @benchmark $A ⋅ $a
ta = @benchmark $B * $b
printrow("A ⋅ a")
tt = @benchmark $A ⋅ $A
ta = @benchmark $B * $B
printrow("A ⋅ A")
tt = @benchmark $As ⋅ $As
ta = @benchmark $Bs * $Bs
printrow("As ⋅ As")
printheader("Double contraction")
tt = @benchmark $A ⊡ $A
ta = @benchmark $B ⋅ $B
printrow("A ⊡ A")
tt = @benchmark $As ⊡ $As
ta = @benchmark $Bsv ⋅ $Bsv
printrow("As ⊡ As")
tt = @benchmark $AA ⊡ $A
ta = @benchmark $BBv * $Bv
printrow("AA ⊡ A")
tt = @benchmark $AA ⊡ $AA
ta = @benchmark $BBv * $BBv
printrow("AA ⊡ AA")
tt = @benchmark $AAs ⊡ $AAs
ta = @benchmark $BBsv * $BBsv
printrow("AAs ⊡ AAs")
tt = @benchmark $As ⊡ $AAs ⊡ $As
ta = @benchmark $Bsv ⋅ ($BBsv * $Bsv)
printrow("As ⊡ AAs ⊡ As")
printheader("Outer product")
tt = @benchmark $a ⊗ $a
ta = @benchmark $b * $(b)'
printrow("a ⊗ a")
tt = @benchmark $A ⊗ $A
ta = @benchmark $Bv * $(Bv)'
printrow("A ⊗ A")
tt = @benchmark $As ⊗ $As
ta = @benchmark $Bsv * $(Bsv)'
printrow("As ⊗ As")
printheader("Other operations")
tt = @benchmark det($A)
ta = @benchmark det($B)
printrow("det(A)")
tt = @benchmark det($As)
ta = @benchmark det($Bs)
printrow("det(As)")
tt = @benchmark inv($A)
ta = @benchmark inv($B)
printrow("inv(A)")
tt = @benchmark inv($As)
ta = @benchmark inv($Bs)
printrow("inv(As)")
tt = @benchmark norm($a)
ta = @benchmark norm($b)
printrow("norm(a)")
tt = @benchmark norm($A)
ta = @benchmark norm($(Bv))
printrow("norm(A)")
tt = @benchmark norm($As)
ta = @benchmark norm($(Bsv))
printrow("norm(As)")
tt = @benchmark norm($AA)
ta = @benchmark norm($(BBv[:]))
printrow("norm(AA)")
tt = @benchmark norm($AAs)
ta = @benchmark norm($(BBsv[:]))
printrow("norm(AAs)")
tt = @benchmark $a × $a
ta = @benchmark $b × $b
printrow("a × a")
# print versioninfo
println(file, """
The benchmarks are generated by
[`benchmark_doc.jl`](https://github.com/Ferrite-FEM/Tensors.jl/blob/master/benchmark/benchmark_doc.jl)
on the following system:
```
julia> versioninfo()
""")
versioninfo(file)
println(file, "```")
end
end