|
1 |
| -local hookInterval = 100 |
| 1 | +local hookInterval = 10000 |
| 2 | +local function calcHookInterval() |
| 3 | + local bogomipsDivider = 0.05 |
| 4 | + local bogomipsDeadline = computer.realTime() + bogomipsDivider |
| 5 | + local ipsCount = 0 |
| 6 | + local bogomipsBusy = true |
| 7 | + local function calcBogoMips() |
| 8 | + ipsCount = ipsCount + hookInterval |
| 9 | + if computer.realTime() > bogomipsDeadline then |
| 10 | + bogomipsBusy = false |
| 11 | + end |
| 12 | + end |
| 13 | + -- The following is a bit of nonsensical-seeming code attempting |
| 14 | + -- to cover Lua's VM sufficiently for the IPS calculation. |
| 15 | + local bogomipsTmpA = {{["b"]=3, ["d"]=9}} |
| 16 | + local function c(k) |
| 17 | + if k <= 2 then |
| 18 | + bogomipsTmpA[1].d = k / 2.0 |
| 19 | + end |
| 20 | + end |
| 21 | + debug.sethook(calcBogoMips, "", hookInterval) |
| 22 | + while bogomipsBusy do |
| 23 | + local st = "" |
| 24 | + for k=2,4 do |
| 25 | + st = st .. "a" .. k |
| 26 | + c(k) |
| 27 | + if k >= 3 then |
| 28 | + bogomipsTmpA[1].b = bogomipsTmpA[1].b * (k ^ k) |
| 29 | + end |
| 30 | + end |
| 31 | + end |
| 32 | + debug.sethook() |
| 33 | + return ipsCount / bogomipsDivider |
| 34 | +end |
| 35 | + |
| 36 | +local ipsCount = calcHookInterval() |
| 37 | +-- Since our IPS might still be too generous (hookInterval needs to run at most |
| 38 | +-- every 0.05 seconds), we divide it further by 10 relative to that. |
| 39 | +hookInterval = (ipsCount * 0.005) |
| 40 | +if hookInterval < 1000 then hookInterval = 1000 end |
| 41 | + |
2 | 42 | local deadline = math.huge
|
3 | 43 | local hitDeadline = false
|
4 | 44 | local function checkDeadline()
|
|
0 commit comments