summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBenoit Germain <bnt.germain@gmail.com>2011-04-18 08:25:57 +0200
committerBenoit Germain <bnt.germain@gmail.com>2011-04-18 08:26:56 +0200
commit323cd4030044dd2f56ecdfddf360360f98f40362 (patch)
tree51c91bae72a96ee6bf3360c1c1b4beb41b32988b /tests
parent05256f1e75f8583829bbaa7cdf1fb1518b93332a (diff)
parent731726be4ed6d09e50577bea5c9ef742b0c1bcc6 (diff)
downloadlanes-323cd4030044dd2f56ecdfddf360360f98f40362.tar.gz
lanes-323cd4030044dd2f56ecdfddf360360f98f40362.tar.bz2
lanes-323cd4030044dd2f56ecdfddf360360f98f40362.zip
* linda uses a fast FIFO implementation to speed up data exchanges
* new linda:count() method * new linda batched data read mode * proper key type check in all linda methods * fix setup-vc.cmd to support Visual Studio 2010 and Windows 7 64 bits * bugfix: release keeper state mutex at desinit
Diffstat (limited to 'tests')
-rw-r--r--tests/linda_perf.lua223
1 files changed, 223 insertions, 0 deletions
diff --git a/tests/linda_perf.lua b/tests/linda_perf.lua
new file mode 100644
index 0000000..bad0024
--- /dev/null
+++ b/tests/linda_perf.lua
@@ -0,0 +1,223 @@
1require "lanes"
2
3-- this lane eats items in the linda one by one
4local eater = function( l, loop)
5 local val, key = l:receive( "go")
6 for i = 1, loop do
7 local val, key = l:receive( "key")
8 --print( val)
9 end
10 -- print "loop is over"
11 val, key = l:receive( "done")
12 -- print( val)
13end
14
15-- this lane eats items in the linda in batches
16local batched = function( l, loop, batch)
17 local val, key = l:receive( "go")
18 for i = 1, loop/batch do
19 l:receive( l.batched, "key", batch)
20 end
21 print "loop is over"
22 val, key = l:receive( "done")
23 print( val)
24end
25
26local lane_eater_gen = lanes.gen( "*", eater)
27local lane_batched_gen = lanes.gen( "*", batched)
28
29local function ziva( preloop, loop, batch)
30 -- prefill the linda a bit to increase fifo stress
31 local top = math.max( preloop, loop)
32 local l, lane = lanes.linda()
33 local t1 = os.time()
34 for i = 1, preloop do
35 l:send( "key", i)
36 end
37 print( l:count( "key"))
38 if batch then
39 if l.batched then
40 lane = lane_batched_gen( l, top, batch)
41 else
42 print "no batch support in this version of Lanes"
43 lane = lane_eater_gen( l, top)
44 end
45 else
46 lane = lane_eater_gen( l, top)
47 end
48 -- tell the lanes they can start eating data
49 l:send("go", "go")
50 -- send the remainder of the elements while they are consumed
51 if loop > preloop then
52 for i = preloop + 1, loop do
53 l:send( "key", i)
54 end
55 end
56 l:send( "done" ,"are you happy?")
57 lane:join()
58 return os.difftime(os.time(), t1)
59end
60
61local tests =
62{
63 --[[{ 2000000, 0},
64 { 3000000, 0},
65 { 4000000, 0},
66 { 5000000, 0},
67 { 6000000, 0},]]
68 --[[{ 1000000, 2000000},
69 { 2000000, 3000000},
70 { 3000000, 4000000},
71 { 4000000, 5000000},
72 { 5000000, 6000000},]]
73 --[[{ 4000000, 0},
74 { 4000000, 0, 1},
75 { 4000000, 0, 2},
76 { 4000000, 0, 3},
77 { 4000000, 0, 5},
78 { 4000000, 0, 8},
79 { 4000000, 0, 13},
80 { 4000000, 0, 21},
81 { 4000000, 0, 44},]]
82}
83for k, v in pairs( tests) do
84 local pre, loop, batch = v[1], v[2], v[3]
85 print( pre, loop, batch, "duration = " .. ziva( pre, loop, batch))
86end
87
88--[[
89 V 2.1.0:
90 ziva( 20000, 0) -> 4s ziva( 10000, 20000) -> 3s
91 ziva( 30000, 0) -> 8s ziva( 20000, 30000) -> 7s
92 ziva( 40000, 0) -> 15s ziva( 30000, 40000) -> 15s
93 ziva( 50000, 0) -> 24s ziva( 40000, 50000) -> 23s
94 ziva( 60000, 0) -> 34s ziva( 50000, 60000) -> 33s
95
96 SIMPLIFIED:
97 ziva( 20000, 0) -> 4s ziva( 10000, 20000) -> 3s
98 ziva( 30000, 0) -> 9s ziva( 20000, 30000) -> 8s
99 ziva( 40000, 0) -> 15s ziva( 30000, 40000) -> 15s
100 ziva( 50000, 0) -> 25s ziva( 40000, 50000) -> 24s
101 ziva( 60000, 0) -> 35s ziva( 50000, 60000) -> 35s
102
103 FIFO:
104 ziva( 2000000, 0) -> 9s ziva( 1000000, 2000000) -> 33s
105 ziva( 3000000, 0) -> 14s ziva( 2000000, 3000000) -> 40s
106 ziva( 4000000, 0) -> 20s ziva( 3000000, 4000000) -> 27s
107 ziva( 5000000, 0) -> 24s ziva( 4000000, 5000000) -> 42s
108 ziva( 6000000, 0) -> 29s ziva( 5000000, 6000000) -> 55s
109
110 FIFO BATCHED:
111 ziva( 4000000, 0, 1) -> 20s
112 ziva( 4000000, 0, 2) -> 11s
113 ziva( 4000000, 0, 3) -> 7s
114 ziva( 4000000, 0, 5) -> 5s
115 ziva( 4000000, 0, 8) -> 3s
116 ziva( 4000000, 0, 13) -> 3s
117 ziva( 4000000, 0, 21) -> 3s
118 ziva( 4000000, 0, 44) -> 2s
119]]
120
121local function ziva2( preloop, loop, batch)
122 local l = lanes.linda()
123 -- prefill the linda a bit to increase fifo stress
124 local top, step = math.max( preloop, loop), (l.batched and batch) and batch or 1
125 local batch_send, batch_read
126 if l.batched and batch then
127 local batch_values = {}
128 for i = 1, batch do
129 table.insert( batch_values, i)
130 end
131 -- create a function that can send several values in one shot
132 batch_send = function()
133 l:send( "key", unpack( batch_values))
134 end
135 batch_read = function()
136 l:receive( l.batched, "key", batch)
137 end
138 else -- not batched
139 batch_send = function()
140 l:send( "key", top)
141 end
142 batch_read = function()
143 l:receive( "key")
144 end
145 end
146 local t1 = os.time()
147 -- first, prime the linda with some data
148 for i = 1, preloop, step do
149 batch_send()
150 end
151 -- loop that alternatively sends and reads data off the linda
152 if loop > preloop then
153 for i = preloop + 1, loop, step do
154 batch_send()
155 batch_read()
156 end
157 end
158 -- here, we have preloop elements still waiting inside the linda
159 for i = 1, preloop, step do
160 batch_read()
161 end
162 return os.difftime(os.time(), t1)
163end
164
165local tests2 =
166{
167 --[[{ 2000000, 0},
168 { 3000000, 0},
169 { 4000000, 0},
170 { 5000000, 0},
171 { 6000000, 0},
172 { 1000000, 2000000},
173 { 2000000, 3000000},
174 { 3000000, 4000000},
175 { 4000000, 5000000},
176 { 5000000, 6000000},]]
177 { 4000000, 0},
178 { 4000000, 0, 1},
179 { 4000000, 0, 2},
180 { 4000000, 0, 3},
181 { 4000000, 0, 5},
182 { 4000000, 0, 8},
183 { 4000000, 0, 13},
184 { 4000000, 0, 21},
185 { 4000000, 0, 44},
186}
187for k, v in pairs( tests2) do
188 local pre, loop, batch = v[1], v[2], v[3]
189 print( pre, loop, batch, "duration = " .. ziva2( pre, loop, batch))
190end
191
192--[[
193 V 2.1.0:
194 ziva( 20000, 0) -> 3s ziva( 10000, 20000) -> 3s
195 ziva( 30000, 0) -> 8s ziva( 20000, 30000) -> 7s
196 ziva( 40000, 0) -> 15s ziva( 30000, 40000) -> 14s
197 ziva( 50000, 0) -> 24s ziva( 40000, 50000) -> 22s
198 ziva( 60000, 0) -> 34s ziva( 50000, 60000) -> 33s
199
200 SIMPLIFIED:
201 ziva( 20000, 0) -> 4s ziva( 10000, 20000) -> 3s
202 ziva( 30000, 0) -> 8s ziva( 20000, 30000) -> 7s
203 ziva( 40000, 0) -> 14s ziva( 30000, 40000) -> 14s
204 ziva( 50000, 0) -> 23s ziva( 40000, 50000) -> 22s
205 ziva( 60000, 0) -> 33s ziva( 50000, 60000) -> 32s
206
207 FIFO:
208 ziva( 2000000, 0) -> 9s ziva( 1000000, 2000000) -> 14s
209 ziva( 3000000, 0) -> 14s ziva( 2000000, 3000000) -> 23s
210 ziva( 4000000, 0) -> 19s ziva( 3000000, 4000000) -> 23s
211 ziva( 5000000, 0) -> 24s ziva( 4000000, 5000000) -> 32s
212 ziva( 6000000, 0) -> 29s ziva( 5000000, 6000000) -> 33s
213
214 FIFO BATCHED:
215 ziva( 4000000, 0, 1) -> 19s
216 ziva( 4000000, 0, 2) -> 11s
217 ziva( 4000000, 0, 3) -> s
218 ziva( 4000000, 0, 5) -> s
219 ziva( 4000000, 0, 8) -> s
220 ziva( 4000000, 0, 13) -> s
221 ziva( 4000000, 0, 21) -> s
222 ziva( 4000000, 0, 44) -> s
223]]