-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
/
perf2.jl
72 lines (55 loc) · 1.27 KB
/
perf2.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
macro timeit(ex,name)
quote
t = Inf
for i=1:5
t = min(t, @elapsed $ex)
end
println($name, "\t", t*1000)
end
end
srand(1776) # get more consistent times
require("$JULIA_HOME/../../examples/list.jl")
function listn1n2(n1::Int64,n2::Int64)
l1 = Nil{Int64}()
for i=n2:-1:n1
l1 = Cons{Int64}(i,l1)
end
l1
end
@timeit listn1n2(1,10^6) "cons "
gc()
# issue #950
load("$JULIA_HOME/../../examples/gk/gk.jl")
@timeit gk(350,[0.1]) "gk "
# issue #942
require("linalg_sparse.jl")
s = sparse(ones(280,280));
@timeit s*s "sparsemul"
# issue #939
y = [500000:-1:1];
@timeit sortperm(y) "sortperm"
# issue #938
x = 1:600000;
@timeit sparse(x,x,x) "sparserang"
# issue #445
load("$JULIA_HOME/../../examples/stockcorr.jl")
@timeit stockcorr() "stockcorr"
function cmp_with_func(x::Vector, f::Function)
count::Int = 0
for i = 1:length(x)-1
if f(x[i], x[i+1])
count += 1
end
end
return count
end
x = randn(200_000)
@timeit (for n in 1:10; count = cmp_with_func(x, isless) end) "funarg "
function arith_vectorized(b,c,d)
a = b.*c + d + 1.0
end
len = 1_000_000
b = randn(len)
c = randn(len)
d = randn(len)
@timeit (for n in 1:10; a = arith_vectorized(b,c,d); end) "vectoriz"