This repository was archived by the owner on Jan 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspeed.rb
More file actions
executable file
·126 lines (98 loc) · 2.73 KB
/
speed.rb
File metadata and controls
executable file
·126 lines (98 loc) · 2.73 KB
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
#!/usr/bin/ruby
require 'benchmark'
require "#{File.dirname(__FILE__)}/lib/ruby_accelerator"
MULTIPLE = 1_000_000
Benchmark.bmbm do |benchmark|
benchmark.report 'inline op' do
MULTIPLE.times { 1+1 }
end
benchmark.report 'inline op x 10' do
(MULTIPLE / 10).times { 1+1; 1+1; 1+1; 1+1; 1+1; 1+1; 1+1; 1+1; 1+1; 1+1 }
end
benchmark.report 'inline op while loop' do
x = 0
while x < MULTIPLE
1 + 1
x += 1
end
end
benchmark.report 'inline op for loop' do
for i in 1..MULTIPLE
1 + 1
end
end
benchmark.report 'send' do
MULTIPLE.times { 1.send(:+, 1) }
end
benchmark.report 'send x 10' do
(MULTIPLE / 10).times { 1.send(:+, 1); 1.send(:+, 1); 1.send(:+, 1); 1.send(:+, 1); 1.send(:+, 1); 1.send(:+, 1); 1.send(:+, 1); 1.send(:+, 1); 1.send(:+, 1); 1.send(:+, 1); }
end
benchmark.report 'addtest1' do
MULTIPLE.times { RubyAccelerator::addtest1 }
end
benchmark.report 'addtest1_loop' do
RubyAccelerator::addtest1_loop(MULTIPLE) # loop done inside function
end
benchmark.report 'addtest2' do
MULTIPLE.times { RubyAccelerator::addtest2 }
end
benchmark.report 'addtest2 x 10' do
(MULTIPLE / 10).times { RubyAccelerator::addtest2_loop(10) }
end
benchmark.report 'addtest2_loop' do
RubyAccelerator::addtest2_loop(MULTIPLE) # loop done inside function
end
benchmark.report 'addtest3' do
RubyAccelerator::addtest3(MULTIPLE)
end
benchmark.report 'execute' do
RubyAccelerator.execute([
[:block_call, MULTIPLE, :times, [
[:call, 1, :+, 1]
]]
])
end
linear = RubyAccelerator::Assembler.assemble(
[
{
:TIMES => MULTIPLE,
:VALUE => 1
},
[:block, :block],
[:call_0, :r0, :TIMES, :times],
[:return, :r0],
:block,
[:call_1, :void, :VALUE, :+, :VALUE],
[:return, :void]
]
)
benchmark.report 'execute_linear' do
RubyAccelerator.execute_linear(linear)
end
linear10 = RubyAccelerator::Assembler.assemble(
[
{
:TIMES => MULTIPLE / 10,
:VALUE => 1
},
[:block, :block],
[:call_0, :r0, :TIMES, :times],
[:return, :r0],
:block,
[:call_1, :void, :VALUE, :+, :VALUE],
[:call_1, :void, :VALUE, :+, :VALUE],
[:call_1, :void, :VALUE, :+, :VALUE],
[:call_1, :void, :VALUE, :+, :VALUE],
[:call_1, :void, :VALUE, :+, :VALUE],
[:call_1, :void, :VALUE, :+, :VALUE],
[:call_1, :void, :VALUE, :+, :VALUE],
[:call_1, :void, :VALUE, :+, :VALUE],
[:call_1, :void, :VALUE, :+, :VALUE],
[:call_1, :void, :VALUE, :+, :VALUE],
[:return, :void]
]
)
benchmark.report 'execute_linear x 10' do
RubyAccelerator.execute_linear(linear10)
end
end