-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathcompute_time.m
More file actions
61 lines (58 loc) · 850 Bytes
/
compute_time.m
File metadata and controls
61 lines (58 loc) · 850 Bytes
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
a = 1.234; b=2.345;
tic;
for i=1:100000000
a = a+b;
b = a-b;
b = a-b;
end
T1 = toc;
%fprintf('(+,-) time:%f\n',T1);
tic;
for i=1:100000000
a = a+b;
b = a-b;
b = a-b;
a = a+b;
b = a-b;
b = a-b;
end
T2 = toc;
%fprintf('(+,-) time:%f\n',T2);
fprintf('(+,-) time:%f\n',(T2-T1)/3.0);
tic;
for i=1:100000000
a = a*b;
b = a/b;
b = a/b;
end
T1 = toc;
%fprintf('(*,/) time:%f\n',T1);
tic;
for i=1:100000000
a = a*b;
b = a/b;
b = a/b;
a = a*b;
b = a/b;
b = a/b;
end
T2 = toc;
%fprintf('(*,/) time:%f\n',T2);
fprintf('(*,/) time:%f\n',(T2-T1)/3.0);
tic;
for i=1:100000000
a = sin(a);
end
T1 = toc;
tic;
for i=1:100000000
a = sin(b);
b = sin(a);
end
T2 = toc;
fprintf('(sin) time:%f\n', T2-T1);
tic;
for i=1:10000
a = randi(32768,100);
end
fprintf('randi time:%f\n',toc);