diff options
author | Peter Drahoš <drahosp@gmail.com> | 2010-10-01 03:22:32 +0200 |
---|---|---|
committer | Peter Drahoš <drahosp@gmail.com> | 2010-10-01 03:22:32 +0200 |
commit | 89d9c98af1ac352ba4d49d660e61b0853d6e1a86 (patch) | |
tree | 15c56d2ce66b4ab147171c0f674cdb4a435ff13f /tests/launchtest.lua | |
download | lanes-89d9c98af1ac352ba4d49d660e61b0853d6e1a86.tar.gz lanes-89d9c98af1ac352ba4d49d660e61b0853d6e1a86.tar.bz2 lanes-89d9c98af1ac352ba4d49d660e61b0853d6e1a86.zip |
Import to git
Diffstat (limited to 'tests/launchtest.lua')
-rw-r--r-- | tests/launchtest.lua | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/tests/launchtest.lua b/tests/launchtest.lua new file mode 100644 index 0000000..5e3037f --- /dev/null +++ b/tests/launchtest.lua | |||
@@ -0,0 +1,78 @@ | |||
1 | -- | ||
2 | -- LAUNCHTEST.LUA Copyright (c) 2007-08, Asko Kauppi <akauppi@gmail.com> | ||
3 | -- | ||
4 | -- Tests launching speed of N threads | ||
5 | -- | ||
6 | -- Usage: | ||
7 | -- [time] lua -lstrict launchtest.lua [threads] [-libs[=io,os,math,...]] | ||
8 | -- | ||
9 | -- threads: number of threads to launch (like: 2000) :) | ||
10 | -- libs: combination of "os","io","math","package", ... | ||
11 | -- just "-libs" for all libraries | ||
12 | -- | ||
13 | -- Note: | ||
14 | -- One _can_ reach the system threading level, ie. doing 10000 on | ||
15 | -- PowerBook G4: | ||
16 | -- << | ||
17 | -- pthread_create( ref, &a, lane_main, data ) failed @ line 316: 35 | ||
18 | -- Command terminated abnormally. | ||
19 | -- << | ||
20 | -- | ||
21 | -- (Lua Lanes _can_ be made tolerable to such congestion cases. Just | ||
22 | -- currently, it is not. btw, 5000 seems to run okay - system limit | ||
23 | -- being 2040 simultaneous threads) | ||
24 | -- | ||
25 | -- To do: | ||
26 | -- - ... | ||
27 | -- | ||
28 | |||
29 | local N= 1000 -- threads/loops to use | ||
30 | local M= 1000 -- sieves from 1..M | ||
31 | local LIBS= nil -- default: load no libraries | ||
32 | |||
33 | local function HELP() | ||
34 | io.stderr:write( "Usage: lua launchtest.lua [threads] [-libs[=io,os,math,...]]\n" ) | ||
35 | exit(1) | ||
36 | end | ||
37 | |||
38 | local m= require "argtable" | ||
39 | local argtable= assert(m.argtable) | ||
40 | |||
41 | for k,v in pairs( argtable(...) ) do | ||
42 | if k==1 then N= tonumber(v) or HELP() | ||
43 | elseif k=="libs" then LIBS= (v==true) and "*" or v | ||
44 | else HELP() | ||
45 | end | ||
46 | end | ||
47 | |||
48 | require "lanes" | ||
49 | |||
50 | local g= lanes.gen( LIBS, function(i) | ||
51 | --io.stderr:write( i.."\t" ) | ||
52 | return i | ||
53 | end ) | ||
54 | |||
55 | local t= {} | ||
56 | |||
57 | for i=1,N do | ||
58 | t[i]= g(i) | ||
59 | end | ||
60 | |||
61 | if false then | ||
62 | -- just finish here, without waiting for threads to finish | ||
63 | -- | ||
64 | local st= t[N].status | ||
65 | print(st) -- if that is "done", they flew already! :) | ||
66 | else | ||
67 | -- mark that all have been launched, now wait for them to return | ||
68 | -- | ||
69 | io.stderr:write( N.." lanes launched.\n" ) | ||
70 | |||
71 | for i=1,N do | ||
72 | local rc= t[i]:join() | ||
73 | assert( rc==i ) | ||
74 | end | ||
75 | |||
76 | io.stderr:write( N.." lanes finished.\n" ) | ||
77 | end | ||
78 | |||