Skip to content

Instantly share code, notes, and snippets.

@planetA
Created February 28, 2017 09:43
Show Gist options
  • Save planetA/be5e4ddb0905860f5f09d4f31fdca0b1 to your computer and use it in GitHub Desktop.
Save planetA/be5e4ddb0905860f5f09d4f31fdca0b1 to your computer and use it in GitHub Desktop.
Displaying memory usage in bytes.
Filling data structures with 1048576 elements and reporting the per element memory usage.
memory usage per element of a vector<uint32_t> : 4
memory usage per element of a list<uint32_t> : 24
memory usage per element of a deque<uint32_t> : 4.15672
memory usage per element of an unordered_set<uint32_t> : 24.0591
memory usage per element of a set<uint32_t> : 40
Comments :
This is an optimistic estimate: the overhead of the data structure and the allocations is ignored.
Because the per-value overhead might be fixed, the results might be less dramatic with larger elements, such as long strings.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment