3 ms·
Compilers generally never guarantee constant time. The C and C++ standards have no notion of observing timing.
by steerablesafe 6y ago
Compilers generally never guarantee constant time. The C and C++ standards have no notion of observing timing.
- 0xFFC 6y agoWhat is observing timing?
- qznc 6y agoOne could imagine an annotation for if-statements that both branches should run for the same number of instructions or cycles.
- deleted 6y ago[deleted]
- steerablesafe 6y agoI meant "observation of timing".
- nwallin 6y agoTangentially related: C++ does have algorithmic complexity guarantees. For instance, std::unordered_map at() and operator[] are guaranteed to be average case complexity of O(1), and std::nth_element is guaranteed to be average case O(n).
- steerablesafe 6y agoComplexity guarantees for algorithms are often expressed explicitly in numbers of operations, not time [1]. Edit: actually, nth_element is a great example here: https://eel.is/c++draft/alg.nth.element#5 https://eel.is/c++draft/alg.nth.element#5 The complexity requirements for container member functions are often more vague an implicit, but I believe those are also not expressed in terms of time either. It's some other implicitly implied operation. In [2] for example this operation is the construction of a single object. [1] https://eel.is/c++draft/sort#5 https://eel.is/c++draft/sort#5 [2] https://eel.is/c++draft/sequences#vector.cons-5 https://eel.is/c++draft/sequences#vector.cons-5 An other tangentially related part of C++ is <chrono>, but I do not think that there are strict requirements there for precision. At most there is monotonic requirement for steady_clock[3]. [3] https://en.cppreference.com/w/cpp/chrono/steady_clock https://en.cppreference.com/w/cpp/chrono/steady_clock