aboutsummaryrefslogtreecommitdiff
path: root/tests/launchtest.lua
diff options
context:
space:
mode:
authorPeter Drahoš <drahosp@gmail.com>2010-10-01 03:22:32 +0200
committerPeter Drahoš <drahosp@gmail.com>2010-10-01 03:22:32 +0200
commit89d9c98af1ac352ba4d49d660e61b0853d6e1a86 (patch)
tree15c56d2ce66b4ab147171c0f674cdb4a435ff13f /tests/launchtest.lua
downloadlanes-89d9c98af1ac352ba4d49d660e61b0853d6e1a86.tar.gz
lanes-89d9c98af1ac352ba4d49d660e61b0853d6e1a86.tar.bz2
lanes-89d9c98af1ac352ba4d49d660e61b0853d6e1a86.zip
Import to git
Diffstat (limited to 'tests/launchtest.lua')
-rw-r--r--tests/launchtest.lua78
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
29local N= 1000 -- threads/loops to use
30local M= 1000 -- sieves from 1..M
31local LIBS= nil -- default: load no libraries
32
33local function HELP()
34 io.stderr:write( "Usage: lua launchtest.lua [threads] [-libs[=io,os,math,...]]\n" )
35 exit(1)
36end
37
38local m= require "argtable"
39local argtable= assert(m.argtable)
40
41for 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
46end
47
48require "lanes"
49
50local g= lanes.gen( LIBS, function(i)
51 --io.stderr:write( i.."\t" )
52 return i
53 end )
54
55local t= {}
56
57for i=1,N do
58 t[i]= g(i)
59end
60
61if 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! :)
66else
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" )
77end
78