3 ms·
It's not really a matter of code going faster or slower, though. The real difference in speed is infinity/undefined. One version initializes the memory and th
by Dylan16807 5y ago
It's not really a matter of code going faster or slower, though. The real difference in speed is infinity/undefined.
One version initializes the memory and the other one doesn't. There's a lot of subtle ways to cause that in different languages.
- tialaramex 5y agoTechnically it postpones initializing the memory, and then it exits before that is needed. If you actually use the memory, both cases work out the same. There are too many languages where you can easily make the mistake of reading uninitialized memory, and that can't happen here, if you ask to sum() the vector you'll get a zero answer in both cases... and both programs will be similarly slow.
- tialaramex 5y ago(Note that you can't actually "sum" the code sample's wrapper type because it lacks the appropriate operations. I spent a while trying to actually make a working example where I trusted I was measuring something "real" and not artefacts and I eventually gave up. Definitely begin with an actual problem, so that you know what you're trying to do and can measure whether you're doing it or else you may just be wanking)