DEV Community

Discussion on: Fibonacci++

Collapse
 
dwd profile image
Dave Cridland

The timer reports in whatever it feels like. More boringly, it'll be measuring std::chrono::high_resolution::period::type::Denom ticks per std::chrono::high_resolution::period::type::Num seconds - and helpfully it might go backwards, because it's not explicitly stable.

Also, yes - incremental caching is always a good plan with any expensive calculation (or other resource that takes time to obtain). That said, I think my "variables" version is sufficiently fast that you might not need to bother unless you needed the cached values an awful lot.

I thought we might further improve performance (in my vector version, too) by calling seq.reserve(n) just before the for loop - that ought to reduce the memory allocation workload significantly - but in my tests it didn't do much.

Collapse
 
bosley profile image
Bosley

I also think the "variables" version is more than sufficient, just offering another look.

I've noticed that whenever I've used .reserve(n) with vectors nothing really seems to be gained time-wise. Perhaps I haven't used them in a scenario where it would be of real benefit.

Thread Thread
 
dwd profile image
Dave Cridland

No, I think you're right - in most cases, the allocators these days are simply good enough that the marginal benefit of reserving space isn't useful.