lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


List,

I have some behavior I can't explain using a debug hook.
I created a small test. Both the function running and the debug hook only contain a counter.
Now when running with the different debug mask and count values I expected to see large differences in both counters. But there aren't.

These are the mask and count values and the counts returned:
With    c       nil
    loop count :        2888804
    check count:        2888813
With    c       100
    loop count :        2219481
    check count:        2404448
With    c       1000
    loop count :        2480837
    check count:        2493768
With    c       50000
    loop count :        2410984
    check count:        2411308
With    r       nil
    loop count :        2229461
    check count:        2229473
With    r       100
    loop count :        2019846
    check count:        2188178
With    r       1000
    loop count :        2162406
    check count:        2173679
With    r       50000
    loop count :        2325529
    check count:        2325842
With    l       nil
    loop count :        2111964
    check count:        2111971
With    l       100
    loop count :        2001379
    check count:        2168168
With    l       1000
    loop count :        2106344
    check count:        2117323
With    l       50000
    loop count :        2089613
    check count:        2089893

Especially with values "l" and 50000, I would have expected the debug counter to be far lower than the loop counter.
What am I missing? Any help is appreciated.

Thijs

Test script below


local gettime = require("socket").gettime
local t, loopcount, checkcount

local loop = function()
  while t+1>gettime() do loopcount = loopcount + 1 end
end

local hook = function() checkcount = checkcount + 1 end

local test = function(mask, count)
  loopcount = 0
  checkcount = 0
  t = gettime()
  debug.sethook(hook, mask, count)
  loop()
  print("With",mask,count)
  print("    loop count :",loopcount)
  print("    check count:", checkcount)
end

test("c", nil)
test("c", 100)
test("c", 1000)
test("c", 50000)
test("r", nil)
test("r", 100)
test("r", 1000)
test("r", 50000)
test("l", nil)
test("l", 100)
test("l", 1000)
test("l", 50000)