14 ms·
How do you mean, suboptimal? The fully generic version is 2 lines of initialization more than the restricted version. Is 2 lines not an accepted tradeoff for be
by andrepd 9y ago
How do you mean, suboptimal? The fully generic version is 2 lines of initialization more than the restricted version. Is 2 lines not an accepted tradeoff for being able to change the engine, and crucially, to draw numbers from any distribution you want?
Furthermore I bet the generic, templated version is as small and fast as a naive implementation. It's all templates so it's all static code generation.
- deleted 9y ago[deleted]
- gp7 9y agoC++'s rng is bad because it's very easy to set them up incorrectly, and people mostly do. See http://www.pcg-random.org/posts/cpp-seeding-surprises.html http://www.pcg-random.org/posts/cpp-seeding-surprises.html
- copx 9y ago>How do you mean, suboptimal? The fully generic version is 2 lines of initialization more than the restricted version. I.e. a 200% increase in code size! Now imagine that throughout the entire code base. > Is 2 lines not an accepted tradeoff for being able to change the engine, and crucially, to draw numbers from any distribution you want? It is a complete waste if you don't need that functionality. That is the point. Generic solutions solve problems you don't even have, and that comes at a price. >Furthermore I bet the generic, templated version is as small and fast as a naive implementation. It's all templates so it's all static code generation. You kinda missed the point. I did not even specify how random(a,b) was implemented, so making statements about the speed of the compiled code makes no sense here. C++'s templates are another nice example of the cost of generic code, though. They are one of the primary reasons why compiling C++ is so slow / resource intense. They have to be instantiated at compile-time again and again and again.. which is a non-trivial process, much slower to compile than a plain non-generic function call. Also they are historically infamous for producing hard to understand error messages.
- andrepd 9y agoThat is not a 200% increase in code size. It's a fixed two more lines of code, that may or may not translate into a bigger binary (if correctly implemented it probably doesn't, even if it increases compile time a bit). I mean that's just silly. I'll assume you write everything in one-liners, right, since for some reason you find it important to minimise the arbitrary measure of lines of code?