Skip to content

Commit 1c2491c

Browse files
committed
Update comments on double vs float
See also #46
1 parent 571b39c commit 1c2491c

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

08-Considering_Performance.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,13 @@ for (int i = 0; i < 15; ++i)
265265
// obj is still taking up memory for no reason
266266
```
267267

268-
### Prefer `double` to `float`
268+
### Prefer `double` to `float`, But Test First
269269

270-
Operations on `double`s are typically faster than `float`s. However, in vectorized operations, `float` might win out. Analyze the code and find out which is faster for your application!
270+
Depending on the situation and the compiler's ability to optimize, one may be faster over the other. Choosing `float` will result in lower precision and may be slower due to conversions. On vectorizable operations `float` may be faster if you are able to sacrifice precision.
271271

272+
`double` is the recomended default choice as it is the default type for floating point values in C++.
273+
274+
See this [stackoverflow](http://stackoverflow.com/questions/4584637/double-or-float-which-is-faster) discussion for some more information.
272275

273276
### Prefer `++i` to `i++`
274277
... when it is semantically correct. Pre-increment is [faster](http://blog2.emptycrate.com/content/why-i-faster-i-c) than post-increment because it does not require a copy of the object to be made.

0 commit comments

Comments
 (0)