2 ms·
What is the code doing? Most of the time it's waiting for a socket. If it's not doing that, do the equivalent for whatever it is waiting for. If it's CPU-bound,
by immibis 2y ago
What is the code doing? Most of the time it's waiting for a socket. If it's not doing that, do the equivalent for whatever it is waiting for. If it's CPU-bound, add interrupt checks.
- simonw 2y agoPlaces I've wanted to implement this in the past include: - Run a subprocess such as "rg" and terminate early if necessary - Run a SQLite SQL a query that errors if it takes more than a second - Same but for other DBs - MySQL, PostgreSQL, Elastic, Mongo etc - Execute a fragment of JavaScript in something like QuickJS with a time limit - Brute force some kind of algorithm with a time limit - using a library I did not write myself