r/AskComputerScience • u/silvers_puppet • Aug 07 '26
Does empirical complexity analysis in a container on a server pose any problems?
I haven't worked with servers or containers that much and so I wanted to ask if I try to measure the complexity of an algorithm, by repeatedly running the script with larger n, how likely is it that my measurements will be falsified?
If I do the same approach on a desktop the differences in time measurements depending on, memory and other processes running on the computer are negligible. Is there any difference when I am trying to measure on a server while that same server is also handling requests and do you think this is going to cause me problems with assessing the complexity correctly?
4
u/Beregolas Aug 07 '26
This is really a question for server admins and hosting specialists.
In general, you can never be 100% sure that hardware will take the same amount of time when ran repeatadly. In general you will get better data if you can find out how many "steps" your algorithm takes. Some runtimes/implementations allow you to cound CPU cycles, but even that comes with caveats and needs to be done and interpreted properly. (Also I don't quite remember how, it's been over a decade since I last needed this)
From a CS perspective: You also can't perform real complexity analysis with real runtimes like this. All you can do is gather data (including noise) and do statistical analysis on that, to find a curve that matches. This can give you a rough estimate, but you can never be 100% sure that your data is correct, your analysis is correct, and you'll probably be unable to distinguish between similar, but different, runtime classes. For example O(n log(n)) and O(n sqrt(n)) might look similar enough with noise and different factors, that you won't quite be able to be 100% sure.
This is not to say that there is no value in what you are doing, but understand that you are not proving anything. It's just a demonstration that can help you estimate runtime complexity in an informal way.
While I am not a sysadmin expert, this would be a major red flag for me. I would be very careful and not really trust the results that much. After all, a random bystander could (by accident maybe) send 50 requests in a few seconds, and spike the server load, leading to possible spikes in the measurement. At the very least I would log incoming requests, so you can discard runs where too many requests came it at once.
3
u/ghjm MSCS, CS Pro (20+) Aug 07 '26
Regardless of whether you're doing it on a desktop or server, you can't determine the asymptotic complexity of an algorithm empirically. Whatever maximum N you've measured to, you can't know the behavior above that, because you can't know there isn't some higher power or exponential term with a small constant that will blow up the runtime above some threshold.
You can certainly do empirical performance testing, but it's likely to cause more confusion than clarity if you describe this with terminology intended for asymptotic analysis, like big-O notation.
1
u/dmazzoni Aug 07 '26
It’s totally normal to measure empirical runtime on a computer with load. There’s nothing different about a server.
Just repeat your measurements of each n multiple times so that you can show that the error in measurement is low. If you see a lot of variation, it means you’ll have to repeat your experiment a lot more times to get an accurate reading.
Don’t forget about ordering. If you measure n=1000 3 times and then n=2000 3 times, what if the server load increased over the course of the day? To minimize that effect, measure n=1000 and then n=2000 and so on, then go back and repeat all of them again, several times.