In windows, I can get it with vim.env.NUMBER_OF_PROCESSORS.
But I can’t figure it out how to get it in unix system.
os.execute(“nproc”) returns a wrong value.
if fn.has("win32") > 0 then
u.num_of_processers = vim.env.NUMBER_OF_PROCESSORS
elseif fn.has("unix") > 0 then
u.num_of_processers = 4 -- os.execute("nproc") return wrong value
end
You could also use vim.loop.cpu_info() it returns a list of objects with model, speed, and times (idle, irq, nice, sys, user). To count the cores you can get the number of items in the list: #vim.loop.cpu_info().
Note that it will be counting with hyper threads, so actual physical core count might be half of whatever number is returned. But that’s the same for nproc as well