Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
simple GC benchmark and mlockall/munlockall
- Loading branch information
Markus Klotzbuecher
committed
May 29, 2009
1 parent
d14c592
commit 8e33206
Showing
5 changed files
with
217 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
require("rtposix") | ||
|
||
function gen_garbage(num, tabsize) | ||
for n = 1,num do | ||
local t = {} | ||
for i = 1,tabsize do | ||
table.insert(t,i) | ||
end | ||
t = {} | ||
end | ||
end | ||
|
||
-- helpers | ||
function timersub(t1, t0) | ||
local res = {} | ||
if t1.sec == t0.sec then | ||
res.sec = 0 | ||
res.nsec = t1.nsec - t0.nsec | ||
else | ||
res.sec = t1.sec - t0.sec | ||
res.nsec = t1.nsec + 1000000 - t0.sec | ||
|
||
if res.nsec >= 1000000 then | ||
res.sec = res.sec + 1 | ||
res.nsec = res.nsec - 1000000 | ||
end | ||
end | ||
return res | ||
end | ||
|
||
function timercmp(t1, t2) | ||
if(t1.sec > t2.sec) then | ||
return 1 | ||
elseif (t1.sec < t2.sec) then | ||
return -1 | ||
elseif (t1.nsec > t2.nsec) then | ||
return 1 | ||
elseif (t1.nsec < t2.nsec) then | ||
return -1 | ||
else | ||
return 0 | ||
end | ||
end | ||
|
||
function tv2str(t) | ||
return t.sec .. "s" .." " .. t.nsec .. "ns" | ||
end | ||
|
||
function print_stat(s) | ||
print("type: " .. s.type .. ", duration: " .. tv2str(s.dur) .. ", collected: " .. s.mem0 - s.mem1 .. " (" .. s.mem0 .. "/" .. s.mem1 ..")") | ||
end | ||
|
||
-- perform a time gc run | ||
-- type is "collect" for full or "step" for incremental | ||
function timed_gc(type) | ||
local stat = {} | ||
local t0 = {} | ||
local t1 = {} | ||
|
||
stat.type = type | ||
stat.mem0 = collectgarbage("count") | ||
|
||
t0 = rtposix.gettime("MONOTONIC") | ||
collectgarbage("collect") | ||
t1 = rtposix.gettime("MONOTONIC") | ||
|
||
stat.mem1 = collectgarbage("count") | ||
stat.dur = timersub(t1,t0) | ||
|
||
return stat | ||
end | ||
|
||
function stop_gc() | ||
collectgarbage("stop") | ||
print("stopped GC") | ||
end | ||
|
||
function start_gc() | ||
print("starting GC") | ||
collectgarbage("start") | ||
end | ||
|
||
-- initalize things | ||
stats = {} | ||
stats.dur_min = { sec=math.huge, nsec=math.huge } | ||
stats.dur_max = { sec=0, nsec=0 } | ||
|
||
stop_gc() | ||
print("doing initial full collect") | ||
print_stat(timed_gc("collect")) | ||
|
||
for i = 1,10000 do | ||
gen_garbage(100, 1000) | ||
s = timed_gc("step") | ||
|
||
if timercmp(s.dur, stats.dur_min) < 0 then | ||
stats.dur_min = s.dur | ||
end | ||
|
||
if timercmp(s.dur, stats.dur_max) > 0 then | ||
stats.dur_max = s.dur | ||
end | ||
|
||
-- print_stat(s) | ||
end | ||
|
||
print("Statistics") | ||
print("max duration: " .. tv2str(stats.dur_max)) | ||
print("min duration: " .. tv2str(stats.dur_min)) | ||
|
||
|
||
print("doing final full collect") | ||
print_stat(timed_gc("collect")) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require("rtposix") | ||
dofile("../mylib/misc.lua") | ||
|
||
-- clock_getres | ||
print("clock_getres") | ||
pp_table(rtposix.getres("REALTIME")) | ||
|
||
-- nanosleep | ||
print("nanosleep") | ||
sec=0 | ||
nsec=100000000 | ||
print("sleeing for sec=" .. sec .. ", nsec=" .. nsec .. ", retval=", rtposix.nanosleep("REALTIME", "rel", sec, nsec)) | ||
|
||
-- gettime | ||
print("gettime (sleeping 100ms)") | ||
for i=1,3 do | ||
t0 = rtposix.gettime("MONOTONIC") | ||
rtposix.nanosleep("REALTIME", "rel", sec, nsec) | ||
t1 = rtposix.gettime("MONOTONIC") | ||
print("t0: sec=" .. t0.sec .. ", nsec=" .. t0.nsec) | ||
print("t1: sec=" .. t1.sec .. ", nsec=" .. t1.nsec) | ||
end | ||
|
||
-- mlockall/munlockall | ||
|
||
print("mlockall: ", rtposix.mlockall("MCL_CURRENT")) | ||
|
||
t = {} | ||
for i = 1,100 do | ||
table.insert(t, i) | ||
end | ||
|
||
print("munlockall: ", rtposix.munlockall()) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters