cpu: another 10 percent optimization from Joerg
This commit is contained in:
parent
753ce61de0
commit
6522f58011
|
@ -1,7 +1,8 @@
|
||||||
---------------------------------------------------
|
---------------------------------------------------
|
||||||
-- Licensed under the GNU General Public License v2
|
-- Licensed under the GNU General Public License v2
|
||||||
-- * (c) 2010, Adrian C. <anrxc@sysphere.org>
|
-- * (c) 2011, Adrian C. <anrxc@sysphere.org>
|
||||||
-- * (c) 2009, Lucas de Vries <lucas@glacicle.com>
|
-- * (c) 2009, Lucas de Vries <lucas@glacicle.com>
|
||||||
|
-- * (c) 2011, Jörg Thalheim <jthalheim@gmail.com>
|
||||||
---------------------------------------------------
|
---------------------------------------------------
|
||||||
|
|
||||||
-- {{{ Grab environment
|
-- {{{ Grab environment
|
||||||
|
@ -11,7 +12,7 @@ local setmetatable = setmetatable
|
||||||
local math = { floor = math.floor }
|
local math = { floor = math.floor }
|
||||||
local table = { insert = table.insert }
|
local table = { insert = table.insert }
|
||||||
local string = {
|
local string = {
|
||||||
find = string.find,
|
sub = string.sub,
|
||||||
gmatch = string.gmatch
|
gmatch = string.gmatch
|
||||||
}
|
}
|
||||||
-- }}}
|
-- }}}
|
||||||
|
@ -32,12 +33,12 @@ local function worker(format)
|
||||||
|
|
||||||
-- Get CPU stats
|
-- Get CPU stats
|
||||||
for line in io.lines("/proc/stat") do
|
for line in io.lines("/proc/stat") do
|
||||||
if string.find(line, "^cpu") then
|
if string.sub(line, 1, 3) ~= "cpu" then break end
|
||||||
cpu_lines[#cpu_lines+1] = {}
|
|
||||||
|
|
||||||
for i in string.gmatch(line, "[%s]+([%d]+)") do
|
cpu_lines[#cpu_lines+1] = {}
|
||||||
table.insert(cpu_lines[#cpu_lines], i)
|
|
||||||
end
|
for i in string.gmatch(line, "[%s]+([^%s]+)") do
|
||||||
|
table.insert(cpu_lines[#cpu_lines], i)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue