There is a scientific tradition of decades that occupies itself with the measurement/estimation of the productivity/efficiency of firms. The three strands of the literature are Data Envelopment Analysis (DEA), Discriminant Analysis (DA), and Stochastic Frontier Analysis (SFA).
I am familiar with the third one. Stochastic Frontier Analysis starts with the observation that firms do not operate all the time on their efficiency frontier, i.e at maximum efficiency, either due to unanticipated shocks, or because, while competitive market forces may push firms to be efficient, they nevertheless are not that strong or that perfect in their effects in order to make firms to be fully efficient, as it is usually assumed in theoretical models. Therefore, inefficiencies due to organizational problems and the like, may persist.
"Efficiency" in the context of SFA, has many facets: output-oriented technical efficiency, input-oriented technical efficiency, cost-efficiency, revenue efficiency, profit efficiency. All have been developed in the literature. One can choose the approach or approaches most suited to the purpose at hand, and to data availability.
To consider the case of output-oriented technical efficiency, SFA modifies/augments the production function of a firm as
$$Q = F(\mathbf x) + u -v$$
Where $u$ is a zero-mean normal random variable and $u$ is a non-negative random variable (usually specified as a half-normal or as an exponential r.v.). The $v$ component captures the inefficiency (measured in terms of output), while the $u$ component captures stochastic disturbances that may affect production (either positively or negatively). $F(\mathbf x)$ represents the full-efficiency level of output.
Econometrically, this is estimated by using Maximum Likelihood (the least-squares method cannot decompose the error term in its two components), on a data set that contains data on output, and on quantities of input factors (in other words, no more than the usual data set required to estimate a production function).
The estimation procedure itself will provide of course estimates that are averages over the data set. If one wants to rank the firms present in the sample, one can implement the approach developed in Jondrow, J., Knox Lovell, C. A., Materov, I. S., & Schmidt, P. (1982). On the estimation of technical inefficiency in the stochastic frontier production function model. Journal of econometrics, 19(2), 233-238.
A comprehensive book on Stochastic Frontier Analysis is Kumbhakar, S. C., & Lovell, C. K. (2003). Stochastic frontier analysis. Cambridge University Press.