forked from JuliaLang/julia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperf_cat.jl
104 lines (89 loc) · 2.09 KB
/
perf_cat.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
function cat2d_perf(n, iter)
a = rand(n,n)
b = rand(n,n)
for i=1:iter
c = [a b; b a]
end
end
function cat2d_perf2(n, iter)
a = rand(n,n)
b = rand(n,n)
for i=1:iter
c = Array(Float64, 2n, 2n)
c[1:n,1:n] = a
c[1:n,n+1:end] = b
c[n+1:end,1:n] = b
c[n+1:end,n+1:end] = a
#c = [a b; b a]
end
end
@timeit cat2d_perf(5, 20000) "small cat"
@timeit cat2d_perf2(5, 20000) "small cat 2"
@timeit cat2d_perf(500, 2) "large cat"
@timeit cat2d_perf2(500, 2) "large cat 2"
function hcat_perf(n, iter)
a = rand(n,n)
b = rand(n,n)
for i=1:iter
c = [a b b a]
end
end
function hcat_perf2(n, iter)
a = rand(n,n)
b = rand(n,n)
for i=1:iter
c = Array(Float64, n, 4n)
c[:, 1:n] = a
c[:, n+1:2n] = b
c[:, 2n+1:3n] = b
c[:, 3n+1:end] = a
end
end
@timeit hcat_perf(5, 20000) "small hcat"
@timeit hcat_perf2(5, 20000) "small hcat 2"
@timeit hcat_perf(500, 2) "large hcat"
@timeit hcat_perf2(500, 2) "large hcat 2"
function vcat_perf(n, iter)
a = rand(n,n)
b = rand(n,n)
for i = 1:iter
c = [a, b, b, a]
end
end
function vcat_perf2(n, iter)
a = rand(n,n)
b = rand(n,n)
for i=1:iter
c = Array(Float64, 4n, n)
c[1:n, :] = a
c[n+1:2n, :] = b
c[2n+1:3n, :] = b
c[3n+1:4n, :] = a
end
end
@timeit vcat_perf(5, 20000) "small vcat"
@timeit vcat_perf2(5, 20000) "small vcat 2"
@timeit vcat_perf(500, 2) "large vcat"
@timeit vcat_perf2(500, 2) "large vcat 2"
function catnd_perf(n, iter)
a = rand(1,n,n,1)
b = rand(1,n,n)
for i = 1:iter
c = cat(3, a, b, b, a)
end
end
function catnd_perf2(n, iter)
a = rand(1,n,n,1)
b = rand(1,n,n)
for i = 1:iter
c = Array(Float64, 1, n, 4n, 1)
c[1,:,1:n,1] = a
c[1,:,n+1:2n,1] = b
c[1,:,2n+1:3n,1] = b
c[1,:,3n+1:4n,1] = a
end
end
@timeit catnd_perf(5, 20000) "small catnd"
@timeit catnd_perf2(5, 20000) "small catnd 2"
@timeit catnd_perf(500, 2) "large catnd"
@timeit catnd_perf2(500, 2) "large catnd 2"